defaultScope

hi,

was wondering if new defaultScope() was supposed to be called for every query on the model

it does not seem to be the case at the moment (rev 1005)

calling a find operation directly on the model works

not with lazy loading nor 'with' in an eager call

this can be seen adding  a defaultScope to the Event model in the test app I attached to the thread about named scopes

http://www.yiiframew…pic,2037.0.html :



public function defaultScope() {


	


		Yii::trace('DEFAULT SCOPE CALLED');


		


		return array(


		


			'condition' => 'Event.name LIKE :search',


			'params' => array(':search' => '%Event%')


		


		);


	


	}

and then adding to the site/index view :

<h3>ALL EVENTs DIRECTLY</h3>


<p>





</p>


<?php 


	


	Yii::trace('INACTIVE events for artists');





	$events = Event::model()->findAll();


	


	echo '<ul>';


	


	foreach($events as $event) {


		


		echo '<li>' . $event->name . '</li>';


		


		echo '<p>number of artists: ' . count($event->artists) . '</p>';


		


		echo '<ul>';


		


			foreach($event->artists as $artist) {


				


				echo '<li>' . $artist->name . '</li>';


				


			}


			


		echo '</ul><br>';


		


	}


	


	echo '</ul>';





?>

rename an event in the db with something that does not contain Event.

the last test show only 3 events

the previous tests show all events regardless of the defaultScope

hope i'm not overlooking something obvious

Good catch. I just checked in the fix. Please help test it. Thanks!

hi qiang

thanks for the fixes !!

everything seems ok for named scopes

but the defaultScope thing now returns an error :

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Event.name' in 'on clause'

the query :

SELECT Artist.id AS t0_c0, t1.id AS t1_c0, t1.name AS t1_c1, t1.active AS t1_c2 FROM Artist LEFT OUTER JOIN ArtistEvent events_t1 ON (Artist.id=events_t1.Artist_id) LEFT OUTER JOIN Event t1 ON (t1.id=events_t1.Event_id) AND (Event.name LIKE :search) WHERE (Artist.id IN (1, 2))

missing attributes in select to satifsfy the on clause ?

It's because of table alias.

thanks,

my bad

good luck for the 1.0.5

really great release I feel