Hello everyone,
Laravel : v8.83.5 PHP : 7.4.28 MariaDB : 10.3.34-MariaDB
I have a very strange error with hasOneThrough.
Let's consider the Orders table with this relationship :
return $this->hasOneThrough(Corporation::class, Offer::class, 'id', 'id', 'offer_id', 'corporation_id') ;
When i execute this code :
$orders = Order::query()
->with(['seller'])
->limit(3482)
->get();
$order = $orders->first();
dump('offer: ' . $order->offer_id );
dump('order: ' . $order->id );
dump('seller: ' . optional($order->seller)->id );
The lazyloading of seller is empty
^ "offer: 4"
^ "order: 1"
^ "seller: "
But when i execute this code :
$orders = Order::query()
->with(['seller'])
->limit(3481)
->get();
$order = $orders->first();
dump('offer: ' . $order->offer_id );
dump('order: ' . $order->id );
dump('seller: ' . optional($order->seller)->id );
The lazyloading of seller is filled
^ "offer: 4"
^ "order: 1"
^ "seller: 2"
The difference between the too is the limit who in first case return 1000 offers then the second return 999 offers.
First case :
^ "select * from `orders` limit 3482"
^ []
^ "select `corporations`.*, `offers`.`id` as `laravel_through_key` from `corporations` inner join `offers` on `offers`.`corporation_id` = `corporations`.`id` where ▶"
^ array:1000 [▼
0 => 1
1 => 4
2 => 6
3 => 9
4 => 11
5 => 29
6 => 32
Second case :
^ "select * from `orders` limit 3481"
^ []
^ "select `corporations`.*, `offers`.`id` as `laravel_through_key` from `corporations` inner join `offers` on `offers`.`corporation_id` = `corporations`.`id` where ▶"
^ array:999 [▼
0 => 1
1 => 4
2 => 6
3 => 9
4 => 11
5 => 29
Any idea about the limit of 999 ?
Thanks in advance
MariaDB limits of 999 placeholders in IN clause.
Solution : multiple IN clause with max 999 each or chunck/lazy/lazyById method
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community