Fixing pivot on has_one aswell as properly indenting

This commit is contained in:
Vinícius Fragoso 2012-10-07 12:15:57 -03:00
parent f36446bd10
commit f6c7cf2dcd
1 changed files with 4 additions and 2 deletions

View File

@ -41,18 +41,20 @@ public function match($relationship, &$parents, $children)
$children_hash = array(); $children_hash = array();
foreach ($children as $child) foreach ($children as $child)
{ {
if (array_key_exists($child->pivot->$foreign, $children_hash)) if (array_key_exists($child->$foreign, $children_hash))
{ {
continue; continue;
} }
$children_hash[$child->pivot->$foreign] = $child; $children_hash[$child->$foreign] = $child;
} }
foreach ($parents as $parent) foreach ($parents as $parent)
{ {
if (array_key_exists($parent->get_key(), $children_hash)) if (array_key_exists($parent->get_key(), $children_hash))
{
$parent->relationships[$relationship] = $children_hash[$parent->get_key()]; $parent->relationships[$relationship] = $children_hash[$parent->get_key()];
}
} }
} }