Failed Conditions
Push — 186-self-joins-fail-in-relatio... ( ba3e0e...5bcaaa )
by Bas
08:01 queued 40s
created

getRelationExistenceQueryForSelfJoin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Eloquent\Relations;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Database\Eloquent\Relations\BelongsToMany as IlluminateBelongsToMany;
9
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\Concerns\InteractsWithPivotTable;
10
use LaravelFreelancerNL\Aranguent\Eloquent\Relations\Concerns\IsAranguentRelation;
11
12
class BelongsToMany extends IlluminateBelongsToMany
13
{
14
    use IsAranguentRelation;
15
    use InteractsWithPivotTable;
16
17
    /**
18
     * Add the constraints for a relationship query on the same table.
19
     *
20
     * @param  \Illuminate\Database\Eloquent\Builder<TRelatedModel>  $query
21
     * @param  \Illuminate\Database\Eloquent\Builder<TDeclaringModel>  $parentQuery
22
     * @param  array|mixed  $columns
23
     * @return \Illuminate\Database\Eloquent\Builder<TRelatedModel>
24
     */
25
    public function getRelationExistenceQueryForSelfJoin(Builder $query, Builder $parentQuery, $columns = ['*'])
26
    {
27
        $query->select($columns);
28
29
        $query->from($this->related->getTable().' as '.$hash = $this->getRelationCountHash());
0 ignored issues
show
Unused Code introduced by
The assignment to $hash is dead and can be removed.
Loading history...
30
31
//        $this->related->setTable($hash);
32
33
        $this->performJoin($query);
34
35
        return parent::getRelationExistenceQuery($query, $parentQuery, $columns);
36
    }
37
}
38