1 | <?php |
||||||
2 | |||||||
3 | namespace Staudenmeir\EloquentJsonRelations\Relations\Postgres; |
||||||
4 | |||||||
5 | use Illuminate\Database\Eloquent\Builder; |
||||||
6 | |||||||
7 | trait HasOneOrManyThrough |
||||||
8 | { |
||||||
9 | use IsPostgresRelation; |
||||||
10 | |||||||
11 | /** |
||||||
12 | * Set the join clause on the query. |
||||||
13 | * |
||||||
14 | * @param \Illuminate\Database\Eloquent\Builder|null $query |
||||||
15 | * @return void |
||||||
16 | */ |
||||||
17 | protected function performJoin(?Builder $query = null) |
||||||
18 | { |
||||||
19 | $query = $query ?: $this->query; |
||||||
20 | |||||||
21 | $farKey = $this->jsonColumn($query, $this->throughParent, $this->getQualifiedFarKeyName(), $this->secondLocalKey); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
22 | |||||||
23 | $query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $farKey); |
||||||
0 ignored issues
–
show
It seems like
getQualifiedParentKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
24 | |||||||
25 | if ($this->throughParentSoftDeletes()) { |
||||||
0 ignored issues
–
show
It seems like
throughParentSoftDeletes() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
26 | $query->whereNull($this->throughParent->getQualifiedDeletedAtColumn()); |
||||||
27 | } |
||||||
28 | } |
||||||
29 | |||||||
30 | /** |
||||||
31 | * Add the constraints for a relationship query. |
||||||
32 | * |
||||||
33 | * @param \Illuminate\Database\Eloquent\Builder $query |
||||||
34 | * @param \Illuminate\Database\Eloquent\Builder $parentQuery |
||||||
35 | * @param array|mixed $columns |
||||||
36 | * @return \Illuminate\Database\Eloquent\Builder |
||||||
37 | */ |
||||||
38 | public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*']) |
||||||
39 | { |
||||||
40 | if ($parentQuery->getQuery()->from === $query->getQuery()->from) { |
||||||
41 | return $this->getRelationExistenceQueryForSelfRelation($query, $parentQuery, $columns); |
||||||
42 | } |
||||||
43 | |||||||
44 | if ($parentQuery->getQuery()->from === $this->throughParent->getTable()) { |
||||||
45 | return $this->getRelationExistenceQueryForThroughSelfRelation($query, $parentQuery, $columns); |
||||||
46 | } |
||||||
47 | |||||||
48 | $this->performJoin($query); |
||||||
49 | |||||||
50 | $firstKey = $this->jsonColumn($query, $this->farParent, $this->getQualifiedFirstKeyName(), $this->localKey); |
||||||
0 ignored issues
–
show
It seems like
getQualifiedFirstKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
51 | |||||||
52 | return $query->select($columns)->whereColumn( |
||||||
0 ignored issues
–
show
|
|||||||
53 | $this->getQualifiedLocalKeyName(), |
||||||
0 ignored issues
–
show
It seems like
getQualifiedLocalKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
54 | '=', |
||||||
55 | $firstKey |
||||||
0 ignored issues
–
show
$firstKey of type Illuminate\Database\Query\Expression is incompatible with the type null|string expected by parameter $second of Illuminate\Database\Query\Builder::whereColumn() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
56 | ); |
||||||
57 | } |
||||||
58 | |||||||
59 | /** |
||||||
60 | * Add the constraints for a relationship query on the same table. |
||||||
61 | * |
||||||
62 | * @param \Illuminate\Database\Eloquent\Builder $query |
||||||
63 | * @param \Illuminate\Database\Eloquent\Builder $parentQuery |
||||||
64 | * @param array|mixed $columns |
||||||
65 | * @return \Illuminate\Database\Eloquent\Builder |
||||||
66 | */ |
||||||
67 | public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*']) |
||||||
68 | { |
||||||
69 | $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash()); |
||||||
0 ignored issues
–
show
It seems like
getRelationCountHash() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
70 | |||||||
71 | $farKey = $this->jsonColumn($query, $this->throughParent, $hash.'.'.$this->secondKey, $this->secondLocalKey); |
||||||
72 | |||||||
73 | $query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $farKey); |
||||||
74 | |||||||
75 | $query->getModel()->setTable($hash); |
||||||
76 | |||||||
77 | $firstKey = $this->jsonColumn($query, $this->farParent, $this->getQualifiedFirstKeyName(), $this->localKey); |
||||||
78 | |||||||
79 | return $query->select($columns)->whereColumn( |
||||||
0 ignored issues
–
show
|
|||||||
80 | $parentQuery->getQuery()->from.'.'.$this->localKey, |
||||||
0 ignored issues
–
show
Are you sure
$parentQuery->getQuery()->from of type Illuminate\Database\Query\Expression|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
81 | '=', |
||||||
82 | $firstKey |
||||||
0 ignored issues
–
show
$firstKey of type Illuminate\Database\Query\Expression is incompatible with the type null|string expected by parameter $second of Illuminate\Database\Query\Builder::whereColumn() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
83 | ); |
||||||
84 | } |
||||||
85 | |||||||
86 | /** |
||||||
87 | * Add the constraints for a relationship query on the same table as the through parent. |
||||||
88 | * |
||||||
89 | * @param \Illuminate\Database\Eloquent\Builder $query |
||||||
90 | * @param \Illuminate\Database\Eloquent\Builder $parentQuery |
||||||
91 | * @param array|mixed $columns |
||||||
92 | * @return \Illuminate\Database\Eloquent\Builder |
||||||
93 | */ |
||||||
94 | public function getRelationExistenceQueryForThroughSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*']) |
||||||
95 | { |
||||||
96 | $table = $this->throughParent->getTable().' as '.$hash = $this->getRelationCountHash(); |
||||||
97 | |||||||
98 | $farKey = $this->jsonColumn($query, $this->throughParent, $this->getQualifiedFarKeyName(), $this->secondLocalKey); |
||||||
99 | |||||||
100 | $query->join($table, $hash.'.'.$this->secondLocalKey, '=', $farKey); |
||||||
101 | |||||||
102 | if ($this->throughParentSoftDeletes()) { |
||||||
103 | $query->whereNull($hash.'.'.$this->throughParent->getDeletedAtColumn()); |
||||||
104 | } |
||||||
105 | |||||||
106 | $firstKey = $this->jsonColumn($query, $this->farParent, $hash.'.'.$this->firstKey, $this->localKey); |
||||||
107 | |||||||
108 | return $query->select($columns)->whereColumn( |
||||||
0 ignored issues
–
show
|
|||||||
109 | $parentQuery->getQuery()->from.'.'.$this->localKey, |
||||||
0 ignored issues
–
show
Are you sure
$parentQuery->getQuery()->from of type Illuminate\Database\Query\Expression|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
110 | '=', |
||||||
111 | $firstKey |
||||||
0 ignored issues
–
show
$firstKey of type Illuminate\Database\Query\Expression is incompatible with the type null|string expected by parameter $second of Illuminate\Database\Query\Builder::whereColumn() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
112 | ); |
||||||
113 | } |
||||||
114 | } |
||||||
115 |