Php Laravel 4-车型和配件;一对多
我正试着了解拉威尔的模型&一对多 我有下列表格Php Laravel 4-车型和配件;一对多,php,mysql,laravel-4,Php,Mysql,Laravel 4,我正试着了解拉威尔的模型&一对多 我有下列表格 ww_bookings ----------------------------- booking_id customer_id quote_id ww_quotes ----------------------------- quote_id etc etc etc 我使用sentry进行身份验证,基本上在成功登录时,我希望找到登录用户的id,然后查询ww_预订数据,其中customer_id='logged in user id' 一旦一切
ww_bookings
-----------------------------
booking_id
customer_id
quote_id
ww_quotes
-----------------------------
quote_id
etc
etc
etc
我使用sentry进行身份验证,基本上在成功登录时,我希望找到登录用户的id,然后查询ww_预订数据,其中customer_id='logged in user id'
一旦一切顺利,客户id的所有预订都需要查询找到的每个预订的WWU报价,并带回数据
//Controller
BookingData::find(1)->quotes()->where('quote_id', '=', '1')->get();
//BookingData Model
class BookingData extends Eloquent {
protected $table = 'ww_bookings';
protected $primaryKey = 'customer_id';
public function quotes() {
return $this->hasMany('QuoteData');
}
}
//QuoteData Model
class QuoteData extends Eloquent {
protected $table = 'ww_quotes';
}
我得到以下错误:
未找到列:1054“where子句”中的未知列“ww\U quotes.booking\U data\U id”(SQL:select*fromww\U quotes
whereww\U quotes
booking\U data\U id=1和quote\U id
=1)
有人能帮我吗,这让我发疯了
希望它有意义。我发现有两个问题: 错误关系
问题是
ww_quotes
schema/table应该包含引用ww_booking
schema/table的键-正好相反。解决办法:
ww_bookings
-----------------------------
customer_id
quote_id
ww_quotes
-----------------------------
quote_id
booking_id
键将不匹配Eloquent生成并用于关系的键名将与现有键名不匹配。如果您指定了它们,请雄辩地使用它们
return $this->hasMany('QuoteData', 'booking_id');
谢谢Andre,但是这会起作用吗,因为一个客户可以根据他们的客户id进行多次预订??