I have to retrieve the “rel1” and “rel2” for two line of the AC class so i must set a different alias for the “rel1” relation but i don’t know how to do.
I have a Translation table which contains a foreign key to a language line of the current translation.
To retrieve the language code of each translation automatically, i set a "defaultScope" on the Translation model, which retrieve the language information with each Translation.
But an alias clash is coming when i try for example to retrieve the translation of the title and description of an article of my blog (example). Two translation have to be retrieve but the alias is the same.
Should i always define full relations with "with" methods and do not use "defaultScope()" to avoid this ?
This is the way i manage translations in my database.
So, i set a defaultScope() on Translation like this :
public function defaultScope() {
return array(
'with' => array(
'fkLanguage'
)
);
}
and then i want to fetch all articles with their title and content :
Article::model()->with('fkTitleTranslationGroup.translations', 'fkContentTranslationGroup.translations')->findAll();
// "translations" is the HAS_MANY relation to Translation table
This code throws SQL error because the same alias is used for relation "fkLanguage" for the two translations fetched.