Total Complexity | 5 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | class HasManyThrough extends BaseHasManyThrough |
||
15 | { |
||
16 | use Relation, Pivot; |
||
|
|||
17 | |||
18 | /** |
||
19 | * Match the eagerly loaded results to their parents. |
||
20 | * |
||
21 | * @param array $models |
||
22 | * @param Collection $results |
||
23 | * @param string $relation |
||
24 | * @return array|stdClass[] |
||
25 | */ |
||
26 | 1 | protected function matchSimple(array &$models, Collection $results, $relation) |
|
27 | { |
||
28 | 1 | $dictionary = []; |
|
29 | |||
30 | 1 | foreach ($results as $result) { |
|
31 | 1 | $dictionary[ModelAccessor::get($result, 'laravel_through_key')][] = $result; |
|
32 | } |
||
33 | |||
34 | 1 | foreach ($models as &$model) { |
|
35 | 1 | $value = []; |
|
36 | |||
37 | 1 | if (isset($dictionary[$key = ModelAccessor::get($model, $this->parent->getKeyName())])) { |
|
38 | 1 | $value = $dictionary[$key]; |
|
39 | } |
||
40 | |||
41 | 1 | ModelAccessor::set($model, $relation, Collection::make($value)); |
|
42 | } |
||
43 | 1 | unset($model); |
|
44 | |||
45 | 1 | return $models; |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * Set the constraints for an eager load of the relation. |
||
50 | * |
||
51 | * @param array $models |
||
52 | * @return void |
||
53 | */ |
||
54 | 1 | public function addEagerConstraintsSimple(array $models) |
|
59 | 1 | } |
|
60 | } |
||
61 |