1: <?php namespace Laravel\Database\Eloquent\Relationships;
2:
3: class Has_One extends Has_One_Or_Many {
4:
5: /**
6: * Get the properly hydrated results for the relationship.
7: *
8: * @return Model
9: */
10: public function results()
11: {
12: return parent::first();
13: }
14:
15: /**
16: * Initialize a relationship on an array of parent models.
17: *
18: * @param array $parents
19: * @param string $relationship
20: * @return void
21: */
22: public function initialize(&$parents, $relationship)
23: {
24: foreach ($parents as &$parent)
25: {
26: $parent->relationships[$relationship] = null;
27: }
28: }
29:
30: /**
31: * Match eagerly loaded child models to their parent models.
32: *
33: * @param array $parents
34: * @param array $children
35: * @return void
36: */
37: public function match($relationship, &$parents, $children)
38: {
39: $foreign = $this->foreign_key();
40:
41: $dictionary = array();
42:
43: foreach ($children as $child)
44: {
45: $dictionary[$child->$foreign] = $child;
46: }
47:
48: foreach ($parents as $parent)
49: {
50: if (array_key_exists($key = $parent->get_key(), $dictionary))
51: {
52: $parent->relationships[$relationship] = $dictionary[$key];
53: }
54: }
55: }
56:
57: }