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

@@ -87,9 +87,14 @@ class Belongs_To extends Relationship {
foreach ($children as &$child)
{
if (array_key_exists($child->$foreign, $parents))
$parent = array_first($parents, function($k, $v) use ($child, $foreign)
{
$child->relationships[$relationship] = $parents[$child->$foreign];
return $v->get_key() == $child->$foreign;
});
if ( ! is_null($parent))
{
$child->relationships[$relationship] = $parent;
}
}
}