【发布时间】:2015-06-27 09:54:49
【问题描述】:
是否可以在两列上建立 hasMany 关系?
我的表格有两列,user_id 和 related_user_id。
我希望我的关系匹配任一列。
在我的模型中我有
public function userRelations()
{
return $this->hasMany('App\UserRelation');
}
哪个运行查询:select * from user_relations where user_relations.user_id in ('17', '18')。
我需要运行的查询是:
select * from user_relations where user_relations.user_id = 17 OR user_relations.related_user_id = 17
编辑:
我正在使用急切加载,我认为这会影响它的工作方式。
$cause = Cause::with('donations.user.userRelations')->where('active', '=', 1)->first();
【问题讨论】:
-
也许最好只通过这两列过滤
UserRelation模型?
标签: php laravel eloquent laravel-5