| Total Complexity | 8 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| 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 | 40 | public function addEagerConstraints(array $models) |
|
| 16 | { |
||
| 17 | 40 | if ($this->customEagerConstraintsCallback) { |
|
| 18 | 12 | ($this->customEagerConstraintsCallback)($this->query, $models); |
|
| 19 | 12 | return; |
|
| 20 | } |
||
| 21 | |||
| 22 | 28 | if ($this->hasLeadingCompositeKey()) { |
|
|
|
|||
| 23 | 4 | $this->addEagerConstraintsWithCompositeKey($models); |
|
| 24 | } else { |
||
| 25 | 24 | parent::addEagerConstraints($models); |
|
| 26 | |||
| 27 | 24 | if (is_array($this->foreignKeys[0])) { |
|
| 28 | 2 | $this->query->where( |
|
| 29 | 2 | $this->throughParent->qualifyColumn($this->foreignKeys[0][0]), |
|
| 30 | 2 | '=', |
|
| 31 | 2 | $this->farParent->getMorphClass() |
|
| 32 | 2 | ); |
|
| 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 | 36 | public function match(array $models, Collection $results, $relation) |
|
| 60 | } |
||
| 61 | } |
||
| 62 |