我正在尝试在fuelphp中过滤orm查询。是否可以检查相关模型的属性?我想获取相关的“评论”,但前提是它们的可见性属性为“0”。是否可以在同一个查询中执行此操作?
这是我当前的查询,它获取相关评论:
$top_rated = \Services\Model_Org::query()
->related('org')
->related('profile_image')
->related('comments')
->where('rating','!=', 'null')
->order_by('rating','desc')
->get();
这是我的尝试,但肯定行不通,因为“可见性”只是评论的属性,而不是组织的属性。
$top_rated = \Services\Model_Org::query()
->related('org')
->related('profile_image')
->related('comments')
->where('visibility', '=', '0')
->where('rating','!=', 'null')
->order_by('rating','desc')
->get();
最佳答案
如果其他人遇到这个问题,这就是有效的方法。
$top_rated = \Services\Model_Org::query()
->related('org')
->related('profile_image')
->related( array(
'comments' => array(
'where' => array(
array('visible' , '=' , '0')
)
)
)
)
->where('rating','!=', 'null')
->order_by('rating','desc')
->get();
关于php - 如何在 FuelPHP 中的关系查询中添加条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25333503/