This is my controller actionpublic function actionIndex() { //Supervisor non possono vedere brani OPEN //Gerard (manager) non puo' vedere OPEN/REJECTED/PROPOSED/CLOSED //Editor non puo' vedere APERTO/PROPOSTO/REJECTED se non suo $with = array( 'propostoCount', 'pubblicatoCount', 'pendingCount', 'apertoCount', 'rifiutatoCount', 'chiusiCount', ); $condition = 'propostoCount=1 AND pubblicatoCount=1 AND pendingCount=1 AND rifiutatoCount=1 AND chiusiCount>0'; $dataProvider=new CActiveDataProvider('Brano', array( 'criteria'=>array( 'with'=>$with, 'condition'=>$condition, 'order'=>'id DESC', ), 'pagination'=>array( 'pageSize'=>5, ), )); $this->render('index',array( 'dataProvider'=>$dataProvider, )); }And these are my relations in Brano Model:public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'proposto' => array(self::HAS_ONE, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_PROPOSED, 'order'=>'ultimo_aggiornamento DESC'), 'pubblicato' => array(self::HAS_ONE, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_PUBLISHED, 'order'=>'ultimo_aggiornamento DESC'), 'pending' => array(self::HAS_ONE, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_PENDING, 'order'=>'ultimo_aggiornamento DESC'), 'aperto' => array(self::HAS_ONE, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_OPEN, 'order'=>'ultimo_aggiornamento DESC'), 'rifiutato' => array(self::HAS_ONE, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_REJECTED, 'order'=>'ultimo_aggiornamento DESC'), 'chiusi' => array(self::HAS_MANY, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_CLOSED, 'order'=>'ultimo_aggiornamento DESC'), 'propostoCount'=>array(self::STAT, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_PROPOSED ), 'pubblicatoCount'=>array(self::STAT, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_PUBLISHED ), 'pendingCount'=>array(self::STAT, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_PENDING ), 'apertoCount'=>array(self::STAT, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_OPEN ), 'rifiutatoCount'=>array(self::STAT, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_REJECTED ), 'chiusiCount'=>array(self::STAT, 'BranoVersione', 'brano_id', 'condition'=>'stato='.BranoVersione::STATUS_CLOSED ), ); }When I try to run it it says:CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'propostoCount' in 'where clause'. The SQL statement executed was: SELECT COUNT(DISTINCT t.id) FROM brano t WHERE (propostoCount=1 AND pubblicatoCount=1 AND pendingCount=1 AND rifiutatoCount=1 AND chiusiCount>0) 解决方案 I can see what you're trying to do here, compare the STAT relations value in the query right? I ran into this same issue, but STAT relations aren't implemented that way. They're pulled from the database in a seperate query so are only available for use within PHP not in the SQL itself. If you want to have a condition using the STAT relationship, you'll have to redefine it inside the query as a full sub-select (or something depending on the query type). 这篇关于在 CActiveDataProvider 条件中使用 STAT 关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 02:55