Laravel Framework 8.61.0
Model/Order.php
<?php
class Order extends Model
{
public client(): HasOne
{
return $this->hasOne(Client::class, 'customer_fk', 'customer_key');
}
}
This is a simple example for me to build the relationship with order and client, I can get client name without using eager loading, which means the relationship should be correct, but I don't want to have N+1 problems so I need eager loading, it's working perfectly on the same version of PHP and Laravel on MySQL, how to fix it on mssql?
<?php
$order = Order::find(1);
echo $order->client->name; // return correct name
$order = Order::with(['client'])->find(1);
echo $order->client->name; // ErrorException : Trying to get property 'name' of non-object