Total Complexity | 8 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | trait HasEagerLoading |
||
8 | { |
||
9 | /** |
||
10 | * Set the constraints for an eager load of the relation. |
||
11 | * |
||
12 | * @param array $models |
||
13 | * @return void |
||
14 | */ |
||
15 | public function addEagerConstraints(array $models) |
||
16 | { |
||
17 | if ($this->customEagerConstraintsCallback) { |
||
18 | ($this->customEagerConstraintsCallback)($this->query, $models); |
||
19 | return; |
||
20 | } |
||
21 | |||
22 | if ($this->hasLeadingCompositeKey()) { |
||
|
|||
23 | $this->addEagerConstraintsWithCompositeKey($models); |
||
24 | } else { |
||
25 | parent::addEagerConstraints($models); |
||
26 | |||
27 | if (is_array($this->foreignKeys[0])) { |
||
28 | $this->query->where( |
||
29 | $this->throughParent->qualifyColumn($this->foreignKeys[0][0]), |
||
30 | '=', |
||
31 | $this->farParent->getMorphClass() |
||
32 | ); |
||
33 | } |
||
34 | } |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Match the eagerly loaded results to their parents. |
||
39 | * |
||
40 | * @param array $models |
||
41 | * @param \Illuminate\Database\Eloquent\Collection $results |
||
42 | * @param string $relation |
||
43 | * @return array |
||
44 | */ |
||
45 | public function match(array $models, Collection $results, $relation) |
||
60 | } |
||
61 | } |
||
62 |