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