Reputation: 905
I have the following code for retrieving both Reservation and ReservationDetail using eager loading:
$reservationsDetail = ReservationDetail::with('reservation')
->whereDate('date_res', '=', Carbon::today()->toDateString())
->toSql();
dd($reservationsDetail);
Which prints this SQL query on browser:
select * from `tbl_reservation_detail` where date(`date_res`) = ?
Shouldn't it be showing the retrieval for the Reservation table as well (tbl_reservation)? How can I make sure it's actually retrieving both (i.e. eager loading is working as expected)?
Btw, I have a BelongsTo relationship on ReservationDetail model:
public function reservation(){
return $this->belongsTo('App\Reservation', 'id_reservation');
}
Upvotes: 0
Views: 1431
Reputation: 942
Retrieving the relationship is a second query. You can make sure it works fine by installing the Laravel Debugbar. It shows all queries, that were executed. dd(DB::getQueryLog());
might also help you out.
Upvotes: 1