:include with conditional on clause?

I have a table I need to eager load however I need an extra condition in
the join clause.

Rails will produce something like this for me

select … from table1 left outer join table2 on table1.table2_id =
table2.id

but what I want is

select … from table1 left outer join table2 on table1.table2_id =
table2.id and table1.some_other_column = 4

Since I don’t see any way to do this using nested includes I tried to
specifify the :joins options instead but then ActiveRecord fails to load
table2 into the association (so that table1.table2 includes what I
selected).

Any ideas?

Thanks,
Kris

I should clarify that in the example I gave above

“select … from table1 left outer join table2 on table1.table2_id =
table2.id and table1.some_other_column = 4”

The number 4 is a parameter. If it were not then I could create a
:condition and pass it to the has_many association.

hi,
I’m not 100% sure but why don’t you put it after the ‘where’ close,
rails wise : in the :condition statement of find ?

in the model when you set up associations you can write somethig like

has_many :table2_items, :conditions => [‘some_other_column = ?’, 4]


Heri R.
http://sprinj.com