I have a laravel application and I've created a relationship between one table and another.
The relationship is a hasOne on my OrderDetail Model
public function customer()
{
return $this->hasOne('App\Customer', 'CU_ACC_CODE', 'OD_ACCOUNT');
}
I'm performing a query on my OrderDetail
$orders = OrderDetail::where('OD_ENTRY_TYPE','S')
->where('OD_STATUS','0')
->where('OD_QTYRESERVED','<>','0')
->select(
DB::raw('CASE WHEN SUM(OD_QTYORD)=SUM(OD_QTYRESERVED)THEN 1 ELSE 0 END AS FullAllocated'),
'OD_ORDER_NUMBER',
DB::raw('SUM(OD_QTYORD) AS Ordered'),
DB::raw('SUM(OD_QTYRESERVED) AS Allocated')
)
->with(['customer' => function($query) {
$query->select('CUNAME');
}])
->groupBy('OD_ORDER_NUMBER')->get();
dd($orders);
And I'm not getting anything back from the customer relation?
The result is null, but I know the relationship is indeed working and there is a link between the two.
Any ideas?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire