0

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?

Ken Shiro
  • 712
  • 10
  • 18

1 Answers1

1

Try the following untested code

'comments' => array(self::HAS_MANY, 'Comment', 'cid','condition'=>'module=:param1 AND section=:param2','params' => array(':param1' => 'quotes',':param2' => 'quote',)),
dInGd0nG
  • 4,162
  • 1
  • 24
  • 37