Criteria Mentioned In Model Class Not Executing From Search Form

I have two fields in the advanced search form(approved, reviewdate) for which I created the radiobuttons.




    <div class="row">

    <?php echo $form->labelEx($model,''); ?>

    <?php

        echo $form->radioButtonList($model,'ReviewedDate',

        array('1' => 'Reviewed', '' => 'Not Reviewed'),

        array(

              'template'=>'{input}{label}',

              'separator'=>'',

              'labelOptions'=>array(

                            'style'=> '

                                      padding-left:13px;

                                      width: 60px;

                                      float: left;

                                     '),

              'onclick' => 'this.form.submit()', 

              'style'=>'float:left;',

              )                             

          );

            ?>

      <div style="clear: both;"></div>

      <?php echo $form->error($model,'ReviewedDate'); ?>

     </div>

                  

            

       <div class="row">

    <?php echo $form->labelEx($model,''); ?>

    <?php

        echo $form->radioButtonList($model,'Approved',

        array('0' => 'Rejected', '1' => 'Approved'),

        array(

              'template'=>'{input}{label}',

              'separator'=>'',

              'labelOptions'=>array(

                            'style'=> '

                                      padding-left:13px;

                                      width: 60px;

                                      float: left;

                                     '),

              'style'=>'float:left;',

              'onclick' => 'this.form.submit()', 

              'uncheck' => NULL,

              )                             

          );

            ?>

      <div style="clear: both;"></div>

      <?php echo $form->error($model,'Approved'); ?>

     </div>

 

Below is the criteria I created for both the fields in model.




    public function search()

    	{

    		// Warning: Please modify the following code to remove attributes that

    		// should not be searched.

    

    		$criteria=new CDbCriteria;

                    $criteria->with=array('apartment');

    		$criteria->compare('t.Id',$this->Id);

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

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

    		$criteria->compare('CreatedDate',$this->CreatedDate,true);

    		$criteria->compare('EmailBody',$this->EmailBody,true);

    		$criteria->compare('MailSubject',$this->MailSubject,true);

                    $criteria->compare('MessageType',1);

    		$criteria->compare('Name',$this->Name,true);

      //              $criteria->compare('ReviewedDate',$this->ReviewedDate);

                     

                    		$criteria->compare('SmsText',$this->SmsText,true);

            	$criteria->compare('UpdatedDate',$this->UpdatedDate,true);

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

    		$criteria->compare('Comments',$this->Comments,true);

    		$criteria->compare('ModifiedBy',$this->ModifiedBy,true);

    

                   

                    if(isset($this->ReviewedDate) )

                    {

                        

                    $criteria->addCondition('ReviewedDate IS NOT NULL');

                    $criteria->addCondition('UpdatedDate > CreatedDate');

                    $criteria->compare('ReviewedDate','0000-00-00 00:00:00');

    

                    }

                    else 

                    {

                    $criteria->addCondition('updateddate = createddate');    

                    $criteria->addCondition('ReviewedDate IS NULL');

                    

                    } 

    

    

                    if ($this->Approved) 

                   {

    

                          $criteria->addCondition("approved='" . $this->Approved . "'");

                          $criteria->condition = ' (updateddate > createddate) AND (revieweddate IS NOT NULL) and approved = 1 ';

                    }

                    else 

                    {

                    

                          $criteria->addCondition("approved='" . $this->Approved . "'");

                          $criteria->condition = ' (updateddate > createddate) AND (revieweddate IS NOT NULL) and approved = 0 ';

                    }

    

                    $criteria->compare('apartment.Name',$this->groupz_search, true);

                    $criteria->compare('apartment.SocietyCode',$this->groupz_code_search, true);

    		return new CActiveDataProvider($this, array(

    			'criteria'=>$criteria,

    		));

    	}



Now when I try click on the reviewed/not reviewed button, the query that should be executed when rejected is clicked gets executed.




    SQL query to be executed - SELECT count(*) FROM `message_template` `t`  LEFT OUTER JOIN `apartment` `apartment` ON (`t`.`ApartmentId`=`apartment`.`Id`)  WHERE (((MessageType=1) AND (updateddate = createddate)) AND (ReviewedDate IS NULL);

 


    SQL executed - SELECT * FROM `message_template` `t`  LEFT OUTER JOIN `apartment` `apartment` ON (`t`.`ApartmentId`=`apartment`.`Id`)  WHERE (((MessageType=1) AND (updateddate > createddate)) AND (ReviewedDate IS NULL) and (Approved=0));



Why is this happening and how can I debug.

[color="#006400"]/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */[/color]

These will overwrite the existing condition as a whole. That is not your intention, I guess. Use "addCondition" instead.