staudenmeir /
eloquent-json-relations
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Staudenmeir\EloquentJsonRelations\Relations\Postgres; |
||||||
| 4 | |||||||
| 5 | use Illuminate\Database\Eloquent\Builder; |
||||||
| 6 | |||||||
| 7 | trait HasOneOrMany |
||||||
| 8 | { |
||||||
| 9 | use IsPostgresRelation; |
||||||
| 10 | |||||||
| 11 | /** |
||||||
| 12 | * Add the constraints for a relationship query. |
||||||
| 13 | * |
||||||
| 14 | * @param \Illuminate\Database\Eloquent\Builder $query |
||||||
| 15 | * @param \Illuminate\Database\Eloquent\Builder $parentQuery |
||||||
| 16 | * @param array|mixed $columns |
||||||
| 17 | * @return \Illuminate\Database\Eloquent\Builder |
||||||
| 18 | */ |
||||||
| 19 | public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*']) |
||||||
| 20 | { |
||||||
| 21 | if ($query->getQuery()->from == $parentQuery->getQuery()->from) { |
||||||
| 22 | return $this->getRelationExistenceQueryForSelfRelation($query, $parentQuery, $columns); |
||||||
| 23 | } |
||||||
| 24 | |||||||
| 25 | $second = $this->jsonColumn($query, $this->parent, $this->getExistenceCompareKey(), $this->localKey); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 26 | |||||||
| 27 | return $query->select($columns)->whereColumn( |
||||||
|
0 ignored issues
–
show
|
|||||||
| 28 | $this->getQualifiedParentKeyName(), |
||||||
|
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
Loading history...
|
|||||||
| 29 | '=', |
||||||
| 30 | $second |
||||||
|
0 ignored issues
–
show
$second 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
Loading history...
|
|||||||
| 31 | ); |
||||||
| 32 | } |
||||||
| 33 | |||||||
| 34 | /** |
||||||
| 35 | * Add the constraints for a relationship query on the same table. |
||||||
| 36 | * |
||||||
| 37 | * @param \Illuminate\Database\Eloquent\Builder $query |
||||||
| 38 | * @param \Illuminate\Database\Eloquent\Builder $parentQuery |
||||||
| 39 | * @param array|mixed $columns |
||||||
| 40 | * @return \Illuminate\Database\Eloquent\Builder |
||||||
| 41 | */ |
||||||
| 42 | public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*']) |
||||||
|
0 ignored issues
–
show
The parameter
$parentQuery is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 43 | { |
||||||
| 44 | $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
Loading history...
|
|||||||
| 45 | |||||||
| 46 | $query->getModel()->setTable($hash); |
||||||
| 47 | |||||||
| 48 | $second = $this->jsonColumn($query, $this->parent, $hash.'.'.$this->getForeignKeyName(), $this->localKey); |
||||||
|
0 ignored issues
–
show
It seems like
getForeignKeyName() 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
Loading history...
|
|||||||
| 49 | |||||||
| 50 | return $query->select($columns)->whereColumn( |
||||||
|
0 ignored issues
–
show
|
|||||||
| 51 | $this->getQualifiedParentKeyName(), |
||||||
| 52 | '=', |
||||||
| 53 | $second |
||||||
|
0 ignored issues
–
show
$second 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
Loading history...
|
|||||||
| 54 | ); |
||||||
| 55 | } |
||||||
| 56 | } |
||||||
| 57 |