Laravel 4 Laravel 4.1 whereHas[完整性约束冲突:1052列';确认';在where子句中不明确]

Laravel 4 Laravel 4.1 whereHas[完整性约束冲突:1052列';确认';在where子句中不明确],laravel-4,eloquent,pivot-table,Laravel 4,Eloquent,Pivot Table,我在使用whereHas时遇到问题,以下是代码: <?php $courses = Course::whereHas('teams', function($q) { $q->where('confirm',1); })->get(); // $courses = Course::has('teams')->get(); ?> 我想做的是得到他们有团队分配给他们的课程 在数据透视表中:'course\u

我在使用whereHas时遇到问题,以下是代码:

<?php    
$courses = Course::whereHas('teams', function($q)    
{
$q->where('confirm',1);                 
})->get();      
// $courses = Course::has('teams')->get();
?>
我想做的是得到他们有团队分配给他们的课程 在数据透视表中:'course\u team'中的'confirm'列为'true'

有()方法,只需获得团队工作良好的课程


如何使其工作?

好吧,作为一个答案:您应该指定与
confirm
相关的表

$q->where('course_team.confirm',1);

当您
连接伪表的多个表时,如果其中出现一列,则可能会发生错误。我的猜测是使用
$q->where('teams.confirm',1)
课程团队。确认
左右。(虽然,我可能错了)谢谢Jari,我使用了我的pivot模型course_team()方法“$q->where('course_team.confirm',1);”并且成功了。很高兴能帮上忙:)我发布了我的答案,所以请随意接受。(打勾)
$q->where('course_team.confirm',1);