English 中文(简体)
采用统计法在计算成本时的关系
原标题:Using STAT relation in CActiveDataProvider criteria
  • 时间:2011-08-12 08:45:23
  •  标签:
  • yii

This is my controller action

public 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,
        ));
    }

这些是我在布拉诺模式中的关系:

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 ),
        );
    }

当我试图管理时,它说:

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).

问题回答

暂无回答




相关问题
how to change a model safe attributes in yii

I have a CActiveRecord model, and I need to change safe attributes list in that model. I have defined the safeAttributes method inside my model, like the following : public function safeAttributes() {...

Accessing a module s action rendered output

I m writing an "Account" module which should take care of everything about accounts: registration, login/logout, user administration, password recovery, account activation, etc. So I thought it would ...

yii components: events and behaviors?

i m currently learning the yii framework and have read their documentation. but i still don t understand the components. what are these. they talk about component events and behaviors. could someone ...

Yii: Customize the results of CAutoComplete

I need to make a dropdown list using CAutoComplete. Everything is set and works fine, here is my code of the action: <?php public function actionSuggestCharacter() { if(Yii::app()->...

热门标签