简体   繁体   English

如何在FuelPHP中为关系查询添加条件?

[英]How to add a condition to relation query in FuelPHP?

I am trying to filter a orm query in fuelphp. 我正在尝试在fuelphp中过滤orm查询。 Is it possible to check a property on the related model? 是否可以检查相关模型上的属性? I want to grab the related "comments" but only if their visibility property is "0". 我想获取相关的“注释”,但前提是它们的可见性属性为“ 0”。 Is it possible to do this in the same query? 是否可以在同一查询中执行此操作?

This is my current query which grabs the related comments: 这是我当前的查询,其中包含相关注释:

$top_rated = \Services\Model_Org::query()
                                    ->related('org')
                                    ->related('profile_image')
                                    ->related('comments')
                                    ->where('rating','!=', 'null')
                                    ->order_by('rating','desc')
                                    ->get();    

This is my attempt which definitely doesn't work because 'visibility' is only a property of the comments not the orgs. 这是我的尝试,但绝对无效,因为“可见性”仅是评论的属性,而不是组织的属性。

$top_rated = \Services\Model_Org::query()
                                    ->related('org')
                                    ->related('profile_image')
                                    ->related('comments')
                                        ->where('visibility', '=', '0')
                                    ->where('rating','!=', 'null')
                                    ->order_by('rating','desc')
                                    ->get();

Here's what worked if anyone else comes across this question. 如果其他人遇到这个问题,这是可行的方法。

$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();    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM