Thanks for reply, in the example above I’ve already used the where option (whith ‘condition’ and ‘params’ ) and also the ‘ON’ option but is not working yet…
with this relation : ‘tableb’=>array(self::HAS_ONE, ‘TableB’, ‘code1, code2, md5(code3)’) In error log I have:
[exception.CDbException] exception ‘CDbException’ with message ‘CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘tableb.md5(code3)’ in ‘where clause’’
Maybe is not possible to make a relation with a foreign key that is a combination of the original key…