1 | <?php |
||||||
2 | |||||||
3 | namespace Volosyuk\SimpleEloquent\Relations; |
||||||
4 | |||||||
5 | use Illuminate\Database\Eloquent\Relations\HasOneThrough as BaseHasOneThrough; |
||||||
6 | use Illuminate\Support\Collection; |
||||||
7 | use Volosyuk\SimpleEloquent\ModelAccessor; |
||||||
8 | |||||||
9 | class HasOneThrough extends BaseHasOneThrough |
||||||
10 | { |
||||||
11 | use Relation, Pivot; |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
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) |
|||||
50 | { |
||||||
51 | 1 | $table = $this->parent->getTable(); |
|||||
52 | |||||||
53 | 1 | $this->query->whereIn($table.'.'.$this->firstKey, $this->getKeys($models, $this->localKey)); |
|||||
0 ignored issues
–
show
The method
whereIn() does not exist on Volosyuk\SimpleEloquent\Builder . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
54 | 1 | } |
|||||
55 | } |
||||||
56 |