Relational Queries over composite PK

How can I create a relation to a table that have a composite PK?

I know I can override primaryKey method to declare my composite Pk, but, relation syntax is (for belongs to):


varName => array(self::BELONGS_TO, 'RefTable', 'RefKey')

So, RefKey doesn’t accept an array as a valid value.

Any ideas?

Did you try:

varName => array(self::BELONGS_TO, ‘’, ‘ON’=>‘RefTable.cloum1 = ThisTable.colum1 AND RefTable.colum2 = ThisTable.colum2’);

?

EDIT: I have not tested this… but is an idea!

Yes, PoL, this work for most cases, but this will generate an error if ‘ThisTable’ is not the alias of your table (this occurs when you model is being used as an related field by a relation of another model).

But I solved this!


varName => array(self::BELONGS_TO, 'RefTable', 'RefKey, RefKey2,...')

Not array delimited, but comma separated. So easy… :P

I think this should be added to the guide.