简体   繁体   English

动态查询yii中的where子句

[英]Dynamic query where clause in yii

I have this query 我有这个查询

$res = propertyDetail::find()
    ->joinWith('propertyImages')
    ->all();

$res = $res->where(['pkPropertyIDPrimary' => 1]);

I receive this error: 我收到此错误:

Call to a member function where() on array 调用成员函数where()的数组

This query contains a property Image and property detail records. 该查询包含属性图像和属性详细信息记录。 Now I want to add a where clause in this dynamic. 现在,我想在此动态中添加一个where子句。

How can I do this? 我怎样才能做到这一点?

You need to do this way, 你需要这样

$res =  propertyDetail::find()
        ->joinWith('propertyImages');

$res = $res->where(['pkPropertyIDPrimary' => 1])->all();

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

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