1 | <?php |
||||||
2 | |||||||
3 | namespace Volosyuk\SimpleEloquent\Relations; |
||||||
4 | |||||||
5 | use Illuminate\Database\Eloquent\Relations\HasManyThrough as BaseHasManyThrough; |
||||||
6 | use Illuminate\Support\Collection; |
||||||
7 | use stdClass; |
||||||
8 | use Volosyuk\SimpleEloquent\ModelAccessor; |
||||||
9 | |||||||
10 | /** |
||||||
11 | * Class HasManyThroughWithSimple |
||||||
12 | * @package Volosyuk\SimpleEloquent |
||||||
13 | */ |
||||||
14 | class HasManyThrough extends BaseHasManyThrough |
||||||
15 | { |
||||||
16 | use Relation, Pivot; |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
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) |
|||||
55 | { |
||||||
56 | 1 | $table = $this->parent->getTable(); |
|||||
57 | |||||||
58 | 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
![]() |
|||||||
59 | 1 | } |
|||||
60 | } |
||||||
61 |