【发布时间】:2021-06-14 16:46:05
【问题描述】:
这是我的代码:
$course = Course::where('id', $activeCourseId)
->with(["blocks.cards" => function($q) use($cardsDueIds) {
$q->whereNotIn('blocks.cards.id', $cardsDueIds);
$q->take(50);
},
"cards",
"blocks.cards.contexts",
"blocks.cards.user_contexts",
"blocks.cards.block.course",
"blocks.cards.thisUser"])
->first();
我尝试只获取block.cards,其中每个block.cards[’id'] 不在$cardsDueIds 中。
其实我有这个错误“
“where 子句”中的未知列“blocks.cards.id”
"。
有人知道如何正确执行此操作吗?谢谢!
【问题讨论】:
-
$q->whereNotIn('blocks.cards.id', $cardsDueIds);到$q->whereNotIn('id', $cardsDueIds);因为你已经在那个关系中回拨 -
它有效,谢谢!
标签: laravel eloquent query-builder relation