Help with composite key

Hello again,

I have a Dictionary table with composite key [font="Lucida Console"](tablename, code)[/font] where a legacy application keeps all table dictionaries.

On the new application there is a class which models customers which has a country associated; so, in [font="Lucida Console"]relations()[/font]:

'dictionaryCountry' => array( self::BELONGS_TO, 'Dictionary', 'country_id',

        'condition' => '`dictionaryCountry`.`tablename` = \'' . DICTIONARY_TYPE_COUNTRY . '\'' ),

Notice that [font="Lucida Console"]tablename[/font] field is a constant ([font="Lucida Console"]DICTIONARY_TYPE_COUNTRY[/font]) and I only need to play with [font="Lucida Console"]Dictionary.code[/font] and [font="Lucida Console"]Customer.country_id[/font], right?

When I need to the access related table from a [font="Lucida Console"]Customer[/font] instance, performing [font="Lucida Console"]Customer->countryDictionary->text[/font] (in order to fetch the country description), it issues an incorrect comparation on the SQL command:

SELECT `dictionaryCountry`.`table` AS `t1_c0`,

`dictionaryCountry`.`code` AS `t1_c1`, `dictionaryCountry`.`text` AS

`t1_c2`, `dictionaryCountry`.`extra1` AS `t1_c3`,

`dictionaryCountry`.`extra2` AS `t1_c4` FROM `Dictionary`

`dictionaryCountry`  WHERE (`dictionaryCountry`.`tablename` = 'country') AND


Notice the condition is font="Lucida Console"[/font] when it should issue as: [font="Lucida Console"]dictionaryCountry.code=:ypl0[/font].

At Dictionary model, I have try to play with [font=“Lucida Console”]primaryKey()[/font] method, testing a few combinations: returning [font=“Lucida Console”]array( ‘tablename’, ‘code’ )[/font], only [font=“Lucida Console”]‘code’[/font] and deleting the method.

At the database, I test to replace the Dictionary table primary key from [font="Lucida Console"](tablename, code)[/font] to [font="Lucida Console"](code, tablename)[/font], without luck…

So, what I missing…?

Really appreciate any clue,


The only solution I have found to avoid this was alter the table and swap columns, so the first column is now [font="Lucida Console"]code[/font] and the second [font="Lucida Console"]tablename[/font].

I think that arrays present in relations() method should respect the order returned on primaryKey(), if exists a composite key; thus avoiding making changes on database tables.

What do you think?