I’m a bit confused how to correctly work with composite foreign keys. The resulting AR query looks good, but the binding is not correct. It uses the (same) primary key for both FK columns, resulting in an empty resultset.
What I have is this:
Table 1:
public function relations()
{
return array(
'table2' => array(self::HAS_ONE, 'Table2', 'table1ID, bookingID'),
);
}
Table 1 has a FOREIGN KEY (`id`, `bookingID`) REFERENCES `Table2` (`table1ID`, `bookingID`),
Table 2:
public function relations()
{
return array(
'table1' => array(self::BELONGS_TO, 'Table1', 'table1ID'),
);
}
I’ve read the manual several times, but can’t find a way to get Yii use the right attributes. Perhaps I have to define something more?
edit:
I also created a new primary key for Table1:
PRIMARY KEY (`id`,`bookingID`)
but no go, and has negative side-effects (findByPk() wants a composite key now of course)