scope and ambiguous columns in relational query

Good day,

i need to do the same thing as described at http://www.yiiframework.com/forum/index.php?/topic/1947-named-scopes-condition-relation-ambiguous-column-name/

but it will not work if relation name do not equals table name

for example:




Category::model()->published()->with('products:published');



in scopes i use alias option equals table name as you suggest.

But if relation name will be not ‘products’ (=table name) but ‘products2’ it will not work, because of in query we will see


SELECT ... FROM `Categories`  LEFT OUTER JOIN `Products` `products2` WHERE ... (Products.published=1)

and Products.published=1 option will cause mysql error.

And i cant set scope alias = products2 because then it will not work with simple queries…

Any workaround?

Oh, now i see how alias option works :slight_smile:

If i will use scope option in every scope declaration will it be the right way?

Can you tell us what you did?

I have solved the problem like this:


public function scopes()

{

	return array(

		'approved'=>array(

			'condition'=>$this->getTableAlias().'.approve = 1',

		),

	);

}