Reputation: 597
I go problem with belongsTo()
relationship as the following.
My Model
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();
}
}
And I will get error column "object_type" does not exist
What should I do with this?
Upvotes: 0
Views: 308
Reputation: 750
In the relationship function, Please model as properly.
May be this is also make an error. If already you Type model.. Do you have Type model..?
You need to use polymorphic concept for this situation.
Upvotes: 6