Problem with HAS_ONE relation on non-primary key (1.1.7)

I have the tables activity and translation with the following properties:

activity:

actId (PK)

actPhraseId

translation:

trId (PK)

trLanguageId

trPhraseId

trText

I am struggling to define a proper relation for the Activity model with the Translation model. Every activity record has one translation for a given language. According to this topic it should be possible to specify a relation on a column other than the primary key. I specified the following relation for the Activity model:




'translation' => array(

	self::HAS_ONE,

	'Translation',

	'',

	'on' => 'actPhraseId = trPhraseId',

	'condition' => 'trLanguageId = 1',

)



(as suggested in the other topic by qiang). Unfortunately this fails:




SQLSTATE[42S22]: Column not found: 1054 Unknown column 'actPhraseId' in  'where clause'. The SQL statement executed was: SELECT  `translation`.`trId` AS `t1_c0`, `translation`.`trPhraseId` AS `t1_c1`,  `translation`.`trLanguageId` AS `t1_c2`, `translation`.`trText` AS  `t1_c3` FROM `translation` `translation`  WHERE (trLanguageId = 1) AND  (actPhraseId = trPhraseId)	



I don’t understand why the on part is converted to a where clause, this seems wrong. Any ideas on how to make this work are greatly appreciated.

Try this




'translation' => array(

        self::BELONGS_TO,

        'Translation',

        '',

        'on' => 't.actPhraseId = translation.trPhraseId',

        'condition' => 'translation.trLanguageId = 1',

)



Edit:

You may need to use a query like this one




$models = Activity::model()->with('translations')->findAll();



(partially tested)

/Tommy

Sorry for the late reply, works great! Thanks.

Great it helped me too :)