|
@@ -38,14 +38,21 @@ class Has_One extends Has_One_Or_Many {
|
|
{
|
|
{
|
|
$foreign = $this->foreign_key();
|
|
$foreign = $this->foreign_key();
|
|
|
|
|
|
- foreach ($parents as &$parent)
|
|
|
|
|
|
+ $children_hash = array();
|
|
|
|
+ foreach ($children as $child)
|
|
{
|
|
{
|
|
- $matching = array_first($children, function($k, $v) use (&$parent, $foreign)
|
|
|
|
|
|
+ if (array_key_exists($child->pivot->$foreign, $children_hash))
|
|
{
|
|
{
|
|
- return $v->$foreign == $parent->get_key();
|
|
|
|
- });
|
|
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $children_hash[$child->pivot->$foreign] = $child;
|
|
|
|
+ }
|
|
|
|
|
|
- $parent->relationships[$relationship] = $matching;
|
|
|
|
|
|
+ foreach ($parents as $parent)
|
|
|
|
+ {
|
|
|
|
+ if (array_key_exists($parent->get_key(), $children_hash))
|
|
|
|
+ $parent->relationships[$relationship] = $children_hash[$parent->get_key()];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|