我有三种模式:Wall,Post和Constraint。他们都有身份证。
Session session = getSession();
Entity object = (Entity)session.load(Entity.class, new Integer(1));
在Wall和Post之间我有一个ManyToMany关系。在该关系的数据透视表中,我有一列constraint_id。当我检索链接到墙的所有帖子时,我还需要在数据透视表中链接的约束。
现在我可以使用withPivot(' constraint_id')方法获取constraint_id。
Post
id
Wall
id
Constraint
id
Post_wall
post_id
wall_id
constraint_id
但我想要的是对象,而不是id。 Laravel有可能吗?
return $this->belongsToMany('App\Wall')
->withPivot('constraint_id')
我也尝试加入约束表,但它没有返回一个对象。
答案 0 :(得分:4)