【发布时间】:2016-09-13 15:11:59
【问题描述】:
我想在另一个关系上使用 where 子句,而不是我当前的选择模型,如下表
table Customer
-------id-----customer_name
Table ModelA
table Customer
-------id-----fk_custome_id
table ModelB
-------id-----fk_ModelA_id
控制器中的功能
$data['data'] = customer::with(['modelA','modelA.modelB'])
->where('fk_customer_id', 2)->get();
客户模型
final function ModalA (){
return $this->hasMany('App\Models\ModelA', 'fk_customer_id', 'id');
}
ModelA 模型
final function Modelb (){
return $this->hasMany('App\Models\ModelB', 'fk_modelA_id', 'id');
}
错误: 我会得到如下错误,因为 select sql 在表 customer 中找不到列名 fk_customer_id,那么我如何在哪里使用 fk_customer_id(在表 ModelA 中)。
【问题讨论】: