Laravel 5.2 whereHas 列不明确
Laravel 5.2 whereHas column is ambiguous
我正在用 laravel 5.2
开发一个项目。但是现在我有一个问题,在我的数据库中,有两个 tables users
和 comments
。 users
table 包含 id, email, username, password, created_at, updated_at
列。 comments
table 包含 id, user_id, content, created_at, updated_at, deleted_at
。现在在我的代码中,我有一个 array
,其中包含一些评论 ID。我想得到 users
谁拥有这些评论。所以这是我的代码:
$commentIds = [
....
...
...
];
$users = User::whereHas('comments',function($query)use($commentIds){
$query->whereIn('id',$commentIds);
});
但是我得到异常说列 id 不明确。
$users = User::whereHas('comments',function($query)use($commentIds){
$query->whereIn('comments.id',$commentIds);
});
会工作
我正在用 laravel 5.2
开发一个项目。但是现在我有一个问题,在我的数据库中,有两个 tables users
和 comments
。 users
table 包含 id, email, username, password, created_at, updated_at
列。 comments
table 包含 id, user_id, content, created_at, updated_at, deleted_at
。现在在我的代码中,我有一个 array
,其中包含一些评论 ID。我想得到 users
谁拥有这些评论。所以这是我的代码:
$commentIds = [
....
...
...
];
$users = User::whereHas('comments',function($query)use($commentIds){
$query->whereIn('id',$commentIds);
});
但是我得到异常说列 id 不明确。
$users = User::whereHas('comments',function($query)use($commentIds){
$query->whereIn('comments.id',$commentIds);
});
会工作