relationships[$relationship] = null; } } /** * Match eagerly loaded child models to their parent models. * * @param array $parents * @param array $children * @return void */ public function match($relationship, &$parents, $children) { $foreign = $this->foreign_key(); $children_hash = array(); foreach ($children as $child) { if (array_key_exists($child->$foreign, $children_hash)) { continue; } $children_hash[$child->$foreign] = $child; } foreach ($parents as $parent) { if (array_key_exists($parent->get_key(), $children_hash)) { $parent->relationships[$relationship] = $children_hash[$parent->get_key()]; } } } }