I want to use composite key in ActiveRecord. I got two tables.
Quotes and Comments. Quotes contains pk - id; Comments pk is composite - module, section, cid
module - module name, where comments come from.
section - section of this module
cid - identificator, in this situaction this is id of quote.
In comments I defined primary key like so.
public function primaryKey()
{
return array('module', 'section', 'cid');
}
Next one, I want to get those records, what related to quotes. So, in Quotes I declared relation:
'comments' => array(self::HAS_MANY, 'Comment', 'module, section, cid', 'params' => array(
':ypl0' => '"quotes"',
':ypl1' => '"quote"',
':ypl2' => 'id'
)),
The required result is:
SELECT * FROM quotes q
LEFT JOIN comments c ON (c.cid = q.id AND module = "quotes" AND section = "quote")
WHERE c.id IS NULL
SQL is working, relation - not. What I'm doing wrong?