4 months ago

L6 Upgrade - Eager Loading Issue with UUID's as ID

Posted 4 months ago by booni3

I have just upgraded to L6 from 5.8.

Eager loading is failing to work on some rows with a basic BelongsTo relationship. If I bypass eager then it works every time, but with it, I get failures (null returned) but only on some records. If I query the same relationship/row without eager it then works.

// With Eager loading
$orders = Order::query()->with(['orderAddress'])->get();

foreach($orders as $order){
    dump($order->orderAddress->first_name); // Fails, but only on some rows
    dump($order->orderAddress()->first()->first_name); // works every time

// Without Eager loading
$orders = Order::all();

foreach($orders as $order){
    dump($order->orderAddress->first_name); // works every time


public function orderAddress() : BelongsTo
    return $this->belongsTo(OrderAddress::class);

When inspecting the eager loading query, it shows the issue:

select * from `order_addresses` where `order_addresses`.`id` in (1, 2, 0, 0, 0, 0, 11189, 0, 122, 140, 199, 1, 1, 1, 100000, 10000, 1, 262, 294409 

The ID's are stored as CHAR 32 UUID's but Eloquent is trying to convert them to integers. Any ideas why?

  • I have incrementing = false; already

Please sign in or create an account to participate in this conversation.