我很难理解拉威尔的hasManyThrough概念.
Bookings
-id (int)
-some other fields
Meta
-id (int)
-booking_id (int)
-metatype_id (int)
-some other fields
MetaType
-id (int)
-name (string)
-some other fields
我试图得到的是一个Eloquent 的模型,它允许我有一个单一的预订记录和多个元类型的元记录.我以为hasManyThrough可能已经解决了这个问题,但现在我想这可能不是最好的办法.
In my booking model I have
public function bookingmeta() {
return $this->hasMany('bookingmeta','booking_id');
}
public function bookingmetatype() {
return $this->hasManyThrough('bookingmetatype','bookingmeta','booking_id','bookingmetatype_id');
}
但是这无法生成正确的SQL并且失败.我得到了
select `new_bookingmetatype`.*, `new_bookingmeta`.`booking_id`
from `new_bookingmetatype`
inner join `new_bookingmeta`
on `new_bookingmeta`.`bookingmetatype_id` = `new_bookingmetatype`.`id`
where `new_bookingmeta`.`booking_id` in (57103)
而我真正想要实现的是
select `new_bookingmetatype`.*, `new_bookingmeta`.`booking_id`
from `new_bookingmetatype`
inner join `new_bookingmeta`
on `new_bookingmeta`.`id` = `new_bookingmetatype`.`bookingmetatype_id`
where `new_bookingmeta`.`booking_id` in (57103)
如果有人能给我指出正确的方向,我会非常感激.谢谢