Merge branch 'staging' into develop

This commit is contained in:
Taylor Otwell 2012-06-28 15:26:25 -05:00
commit 8d17702b9c
1 changed files with 12 additions and 5 deletions

View File

@ -325,14 +325,21 @@ public function match($relationship, &$parents, $children)
{
$foreign = $this->foreign_key();
$dictionary = array();
foreach ($children as $child)
{
$dictionary[$child->pivot->$foreign][] = $child;
}
foreach ($parents as &$parent)
{
$matching = array_filter($children, function($v) use (&$parent, $foreign)
{
return $v->pivot->$foreign == $parent->get_key();
});
$parent_key = $parent->get_key();
$parent->relationships[$relationship] = array_values($matching);
if (isset($dictionary[$parent_key]))
{
$parent->relationships[$relationship] = $dictionary[$parent_key];
}
}
}