The Property « Cdbcriteria.is_Activ » Is Not Defined

Hello !

I’ve had a new field in my table user “is_activ”.

I just added it in phpmyadmin.

But, when I want to search result for is_activ == true, erro occured :


      $criteria=new CDbCriteria(); 

      $criteria->compare('is_activ',true); 

      

      $usersActiv = User::model()->findAll($criteria);


The property « CDbCriteria.is_activ » is not defined

But setting works : $user->is_activ = false without any bugs…

What’s wrong ? :confused:

I couldn’t reproduce the issue you describe, at least reproducing all the steps you mentioned.

Bug still here…

Maybe I mis-defined this field.

Can you tell me which steps are needed in order to add new field ?

Just adding it in BDD is enough ?

I have to files :

BaseUserEvent and UserEvent (whcich extends BaseUserEvent) :




<?php


/**

 * This is the model base class for the table "user_event".

 *

 * Columns in table "user_event" available as properties of the model:

 

      * @property string $user_id

      * @property string $event_id

      * @property integer $user_event_status_id

      * @property string $checkin_id

      * @property bool $is_activ

      * @property bool $get_moovpoint  

 *

 * Relations of table "user_event" available as properties of the model:

 * @property EventActivity[] $eventActivities

 * @property EventSuggestion[] $eventSuggestions

 * @property EventSuggestion[] $eventSuggestions1

 * @property EventThread[] $eventThreads

 */

abstract class BaseUserEvent extends AppActiveRecord {

    

    public static function model($className = __CLASS__) {

        return parent::model($className);

    }


    public function tableName() {

        return 'user_event';

    }


    public function rules() {

        return array(

            array('user_id, event_id', 'required'),

            array('user_event_status_id, checkin_id', 'default', 'setOnEmpty' => true, 'value' => null),

            array('user_event_status_id', 'numerical', 'integerOnly' => true),

            array('user_id, event_id', 'length', 'max' => 10),

            array('checkin_id', 'length', 'max' => 19),

            array('user_id, event_id, user_event_status_id, checkin_id, is_activ, get_moovpoint', 'safe', 'on' => 'search'),

        );

    }

    

    public function __toString() {

        return (string) $this->checkin_id;

    }


    public function behaviors() {

        $behaviors = array(

        'activerecord-relation' => array('class' => 'EActiveRecordRelationBehavior')

);


      return CMap::mergeArray(parent::behaviors(), $behaviors);

    }


    public function relations() {

        return array(

            'eventActivities' => array(self::HAS_MANY, 'EventActivity', 'user_id'),

            'eventSuggestions' => array(self::HAS_MANY, 'EventSuggestion', 'user_id'),

            'eventSuggestions1' => array(self::MANY_MANY, 'EventSuggestion', 'event_suggestion_position(user_id, event_suggestion_id)'),

            'eventThreads' => array(self::HAS_MANY, 'EventThread', 'user_id'),

        );

    }


    public function attributeLabels() {

        return array(

            'user_id' => Yii::t('app', 'User'),

            'event_id' => Yii::t('app', 'Event'),

            'user_event_status_id' => Yii::t('app', 'User Event Status'),

            'checkin_id' => Yii::t('app', 'Checkin'),

            'is_activ' => Yii::t('app', 'Is active'),

            'get_moovpoint' => Yii::t('app', 'Can get MP'),

        );

    }


    public function search() {

        $criteria = new CDbCriteria;


        $criteria->compare('user_id', $this->user_id);

        $criteria->compare('event_id', $this->event_id);

        $criteria->compare('user_event_status_id', $this->user_event_status_id);

        $criteria->compare('checkin_id', $this->checkin_id);

        $criteria->compare('is_activ', $this->is_activ);

        $criteria->compare('get_moovpoint', $this->get_moovpoint);


        return new CActiveDataProvider(get_class($this), array(

                                                          'criteria' => $criteria,

                                                          'pagination' => array(

                                                          'pageSize' => $this->getPageSize(),

                                                          )

                                                        ));

    }

    

}

And UserEvent :


<?php


  Yii::import('app.models.activeRecord._base.BaseUserEvent');


  class UserEvent extends BaseUserEvent

  {

    /**

     *

     * @return UserEvent

     */

    public static function model($className = __CLASS__)

    {

      return parent::model($className);

    }




    /**

     * @param $id

     * @return $this

     */

    public function event($id)

    {

      $criteria = array('condition'=>'t.event_id = :event_id','params'=>array(':event_id'=>$id));

      $this->getDbCriteria()->mergeWith($criteria);

      return $this;

    }


    /**

     * @param $id

     * @return $this

     */

    public function user($id)

    {

      $criteria = array('condition'=>'t.user_id = :user_id','params'=>array(':user_id'=>$id));

      $this->getDbCriteria()->mergeWith($criteria);

      return $this;

    }


        /**

     * @param $bool

     * @return $this

     */

    public function isactiv($bool)

    {

      $criteria = array('condition'=>'t.is_activ = :bool','params'=>array(':bool'=>$bool));

      $this->getDbCriteria()->mergeWith($criteria);

      return $this;

    }




    public function scopes()

    {

       $s = array(

         'in' => array('condition'=>'user_event_status_id='.UserEventStatus::IN,'together'=>true)

       );


      return CMap::mergeArray(parent::scopes(),$s);

    }


    public function relations()

    {

      $r = array(

        'user' => array(self::BELONGS_TO, 'User', 'user_id'),

        'event' => array(self::BELONGS_TO, 'Event', 'event_id'),

      );


      return CMap::mergeArray(parent::relations(), $r);

    }


    public function afterSave()

    {

      if( $this->user_event_status_id != UserEventStatus::IN ) {

        // find all suggestions positions of this user and delete them

        $positions = EventSuggestionPosition::model()->user($this->user_id)->event($this->event_id)->findAll();

        foreach( $positions as $pos ) {

          $pos->delete();

        }

      }


      /**

       * Notify invited user except if it's the event creator

       */

      if( $this->isNewRecord && !$this->notified && $this->user_id != $this->event->user_id) {

        $notification = new NotificationUserEvent($this);

        $notification->send();

      }




      parent::afterSave();

    }

    




}

You just need to add it to your db table.

You may need to refresh db schema (if it’s cached according to a connection configuration) and/or to add a new attribute to a model validation rules to mark it ‘safe’ for a massive assignment.

Why do you mention BDD here? What do you mean?