-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
- Laravel Version: 5.1.*
- PHP Version: 5.5.9
- Database Driver & Version: postgres 9.5.4
Description:
hasManyThrough relation returns empty array always when localKey is not 'id'
Added listener to illuminate.query event and found that in 'where in' instead of localKey the id values are passed.
Output:
(
[0] => select "table_3".*, "table_2"."table_1_id" from "table_3" inner join "table_2" on "table_3"."id" = "table_3"."table_2_id" where "table_2"."table_1_id" in (?, ?, ?) and "table_2"."table_1_id" = ?
[1] => Array
(
[0] => 5
[1] => 7
[2] => 8
[3] => 14
)
[2] => 1.9
[3] => pgsql
)
Steps To Reproduce:
1.)
table_1: id,name,slug,group_id
table_2: id,name,table_1_id -- table_1_id = table_1.group_id
table_3: id,name,link,table_2_id -- table_2_id = table_2.id
2.)
table_1 Model relation:
public function table3()
{
return $this->hasManyThrough(TableThree::class, TableTwo::class,
'table_1_id', 'table_2_id', 'group_id');
}
3.)
TableOne::with(['table3' => function ($q) {
$q->where('table_2.table_1_id', 14);
}]);
In my table_1 for id's 5,7,8 group_id is 14.
When I execute step 3 I see above output but I have specifically mentioned the group_id as localKey.