Unknown where clause in SQL

Hi,

I’m trying to get data with model but it’s querying SQL with conditions which are not called. I couldn’t solve this, i dont know where it is adding this conditions. Any help would be nice Thank you…

[14:54:31.310][trace][system.db.CDbCommand] Querying SQL: SELECT * FROM “medicine_drug_update” “t” WHERE (b[/b] AND (user_changed=:ycp1)) AND b[/b] ORDER BY id DESC LIMIT 10. Bound with :ycp0=‘1’, :ycp1=‘1’, :ycp2=‘1’ in D:\wamp\www\vademecum_admin\protected\views\moderate\myrecords.php (33) in D:\wamp\www\vademecum_admin\protected\controllers\ModerateController.php (60) in D:\wamp\www\vademecum_admin\index.php (13)

myrecords (satır 116)

seperating where clause as (unwanted&&mycondition) && unwanted




[b]AND (status=:ycp2)[/b]

[b](in_book=:ycp0)[/b]


public function actionMyRecords()

	{

		$this->layout='//layouts/column2';

		

		$model= new DrugUpdate;

		$model->user_changed = Yii::app()->user->getId();

		

		$this->render('myrecords', array(

			"model" => $model

		));

	}

it’s render the data with GridView

You could check DrugUpdate.defaultScope(). Could you post the content of your myrecords view?

myrecord’s view.


$this->widget('ext.bootstrap.widgets.BootGridView',array(

	'id'=>'drug-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'drug_id',

		'date_changed',

		'name',

		'company_data.name',

		'drug_type_data.name' ,

		array( 'name'=>'status', 'type' => 'raw', 'value'=>'"<a href=\"#\" rel=\"tooltip\" title=\"".$data->moderation_notification."\">".$data->status."</a>"' ),

		/*'name_book',

		'in_book',

		'date_changed',

		'user_changed',

		'unpublished',

		*/

		

	),

));

where can i check default scopes? drugupdate model has just one scope


public function scopes()

	{

	    return array(

	        'lastRecord'=>array(

	            'condition'=>'"drug_id"='.$this->drug_id,

	            'order'=>'id DESC',

	            'limit'=>1,

	        ),

	    );

	}

Try this:


public function scopes()

        {

            return array(

                'lastRecord'=>array(

                    'condition'=>'drug_id= :drug_id',

                    'params' => array(':drug_id' => $this->drug_id),

                    'order'=>'id DESC',

                    'limit'=>1,

                ),

            );

        }

In the search() method of DrugUpdate model.

Try this:




$model = new DrugUpdate();

$model->unsetAttributes();



Yes, thank you all … :) it’s working but i still dont know why it’s already has this attributes?

Columns in_book and status probably have default values (different than NULL) in your database schema. When a new instance of DrugUpdate gets created its corresponding attributes will have that default values too, and DrugUpdate::search() will filter the result by that attributes.