condition in criteria in yii framework php

前端 未结 2 985
心在旅途
心在旅途 2021-01-23 01:44
$criteria=new CDbCriteria();
$criteria->with = array(\'reviewCount\', \'category10\', \'category20\', \'category30\', \'town\');
$criteria->select = \'t.id,busines         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 02:28

    As far as I know, you can't reference aliases in a WHERE part (proof link). Remove the condition line and add the following:

    $criteria->having = 'COUNT(tbl_abc.id) > 1';
    

    UPDATE

    CActiveDataProvider accepts finder instance, so you'll need a model scope:

     array(
            'with' => array('reviewCount', 'category10', 'category20', 'category30', 'town'),
            'select' => 't.id,business,street,postalCode,contactNo,checkinCount,count(tbl_abc.id) as spcount',
            'join' => 'left join tbl_abc on t.id=tbl_abc.businessId',
            'group' => 't.id',
            'order' => 'spcount DESC',
            'having' => 'COUNT(tbl_abc.id) > 1',
          ),
        );
      }
    }
    
    // usage
    $provider = new CActiveDataProvider(Business::model()->hasSpcount());
    

    Hope this works

提交回复
热议问题