我对belongsTo()
关系的问题如下。
我的模特
class TypeOne extends Model{
}
===============================
class TypeTwo extends Model{
}
===============================
class Post extends Model{
public function typeOne(){
return $this->belongsTo('Type','type_id')->where('object_type','type_one');
}
public function typeTwo(){
return $this->belongsTo('Type','type_id')->where('object_type','type_two');
}
public function getPost(){
return Post::with(['typeOne','typeTwo'])->get();
}
}
我会收到错误column "object_type" does not exist
我该怎么办?
答案 0 :(得分:6)