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