Fix Eloquent eager loading matching.

This commit is contained in:
Taylor Otwell
2012-04-23 16:08:57 -05:00
parent b65fa7040d
commit 94948cf675
8 changed files with 53 additions and 42 deletions

View File

@@ -91,9 +91,14 @@ class Has_Many extends Has_One_Or_Many {
{
$foreign = $this->foreign_key();
foreach ($children as $key => $child)
foreach ($parents as &$parent)
{
$parents[$child->$foreign]->relationships[$relationship][$child->get_key()] = $child;
$matching = array_filter($children, function($v) use ($parent, $foreign)
{
return $v->$foreign == $parent->get_key();
});
$parent->relationships[$relationship] = $matching;
}
}