add a condition to a JOIN in a has_many relationship - bug or intended behavior?

Hi,

I defined a relationship like this


'table2s' => array(self::HAS_MANY,'Table2','fk_id','condition' => 'column1 = 2')

I would expect that if I do $model->table2s I’m getting a query like this




SELECT * 

FROM table1

LEFT OUTER JOIN table2 ON table2.fk_id = table1.id AND column1 = 2



but what I’m getting is this




SELECT * 

FROM table1

LEFT OUTER JOIN table2 ON table2.fk_id = table1.id 

WHERE

column1 = 2



the results from these 2 queries are only the same if you would use an INNER JOIN but when using a LEFT OUTER JOIN it’s not the same.

I think this is probably a bug.

Or is it intended to be that way?

If so, how can I force a condition directly into the JOIN part of the query?

Instead of ‘select’ use the ‘on’ option in your relations().

thanks Mike,

sometimes reading the manual is a good idea :)