named scopes, condition, relation, ambiguous column name

hi all,

I started to use named scopes (yii from subversion)

I have 2 models :

Artist

Event

I set an 'active' named scope on both of them



public function scopes() {


	


	return array(


		


		'active' => array('condition' => 'active = 1'),


		


	);


	


}


everything is fine if I use the named scope like this :



Artist::model()->active()->findAll();


Or



Event::model()->active()->findAll();


but when I start trying to use this named scope in 'with' like so :



Event::model()->active()->with('Artist:active')->findAll();


I then get errors like so :

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘active’ in where clause is ambiguous

If I try to disambiguate the column in the scope condition :



'active' => array('condition' => '??.active = 1'),


it solves the problem but this placeholder triggers an error if I now try this



Artist::model()->active()->findAll();


I get this error :

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘??.active = 1) AND (Artist.id=‘2’))’ at line 1

Am i missing something ?

do I need to set aliases ?

thank you for any help on this

Yes, you need to prepend 'active' with an alias, preferably the table name. You need to specify 'alias' in the scope as well.

ah thanks a lot

does it work too if I set an alias in the relations ?

and what happens if you’re not there to answer all our questions ? ;)

seriously, how can I have an overview of the plans for Yii ?

I really am enjoying it, would like to know if it’s there to stay :)

Yes, setting alias in the relation should also work.

As we approach the release of 1.1, we will expand our dev team and increase the availability of our help. At the same time, our community has been growing rapidly, and many people like you, are offering help to others. My philosophy is that for a framework to truly grow up, it has to be rooted among a strong community.

Quote

My philosophy is that for a framework to truly grow up, it has to be rooted among a strong community.

yes indeed, hope to see yii grow, the spirit of it all makes you want to participate even in small amounts (according to ones abilities)

is it being nosy to ask who is the current dev team ? and do you do this full time ?

Currently the dev team only consists Wei and me. No, we are not doing this full time. We have our own full time job to support our families (and also this project. ;))