I'm working with an older version of Rails and ActiveRecord that does not have the :primary_key
option in has_many
relationships of more recent ActiveRecord versions and unfortunately I don't get to control when we upgrade. Is there any way to hack this solution via :conditions
or :finder_sql
options?
views:
28answers:
1
+1
A:
It should be possible using :finder_sql
e.g.
has_many :foobars, :finder_sql => 'select * from table where foreign_key = #{primary_key}'
Note the use of single quotes around the query so that #{primary_key}
is not expanded at the time when the association is declared.
mikej
2010-03-31 22:12:09