staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels
MIT License
2.67k stars 157 forks source link

id = null in query for unknown reason #53

Closed Skintillion closed 4 years ago

Skintillion commented 4 years ago

Keep getting empty results..

A::first()->e()->toSql()

select * from `e` 
inner join `d` on `d`.`e_id` = `e`.`id` 
inner join `c` on `c`.`d_id` = `d`.`id` 
inner join `b` on `b`.`c_id` = `c`.`id`  
`d`.`deleted_at` is null and 
`c`.`deleted_at` is null and 
`b`.`deleted_at` is null and 
`b`.`id` is null and
`e`.`deleted_at` is null

not sure where the

`b`.`id` is null

is coming from

        return $this->hasManyDeep('App\Models\E', 
            ['App\Models\B', 'App\Models\C','App\Models\D'],
            [
                'id',
                'id',
                'id',
                'id'
            ],
            [
                'b_id',
                'c_id',
                'd_id',
                'e_id'
            ]
        );
Skintillion commented 4 years ago

Fixed myself. Just made a mistake.

         return $this->hasManyDeep('App\Models\E', 
            ['App\Models\B', 'App\Models\C','App\Models\D'],
            [
                'a_id',
                'id',
                'id',
                'id'
            ],
            [
                'id',
                'c_id',
                'd_id',
                'e_id'
            ]
        );