Disambiguating column names in MANY MANY relation

Tables:

registration_page stores instances of RegistrationPage model.

translation stores instances of Translation model.

translation_to_registration_page - holds associations between RegistrationPage and Translation (they’re MANY_MANY).

Model RegistrationPage has following relations:




public function relations()

{

	    return array(

		'descriptionTranslations' => array(

                self::MANY_MANY,

                'Translation',

                '{{translation_to_registration_page}}(page_id, translation_id)',

                'condition' => 'page_item_type = :type', //'page_item_type' is in 'translation_to_registration_page' table

                'params' => array(':type' => 'description'),

                'index' => 'language_code',

            ),

            'titleTranslations' => array(

                self::MANY_MANY,

                'Translation',

                '{{translation_to_registration_page}}(page_id, translation_id)',

                'condition' => 'page_item_type = :type', //'page_item_type' is in 'translation_to_registration_page' table

                'params' => array(':type' => 'title'),

                'index' => 'language_code',

            ),

        );

}



Now I can’t use




    $dataProvider = new CActiveDataProvider('RegistrationPage', array(

            'criteria' => array(

                'order' => 'weight',

                'with' => array('descriptionTranslations', 'titleTranslations'),

            ),



because page_item_type parameter (in associations table) needs to be disambiguated. To do so I used relation name (titleTranslations, descriptionTranslations) BUT this failed because they refer to the table name of Translation model. So, how does association table aliased?

In other words - we have 3 tables:

registration_page - this is main table and aliased as ‘t’.

translation - this is joined table and aliased as relation name (‘titleTranslations’ or ‘descriptionTranslations’).

translation_to_registration_page - this is helper table, how is it aliased? Are there any rules?

I’ve figured out that alias for association table is in form: relationName_relationName, so in my case it’s aliased as ‘descriptionTranslations_descriptionTranslations’ and ‘titleTranslations_titleTranslations’. Is this correct observation?

I’ve modified my condition from




'condition' => 'page_item_type = :type',



to:




'condition' => 'descriptionTranslations_descriptionTranslations.page_item_type = :type',