Has_many + finder_sql

from the api I got:

has_many :subscribers, :class_name => "Person", :finder_sql =>
      'SELECT DISTINCT people.* ' +
      'FROM people p, post_subscriptions ps ' +
      'WHERE ps.post_id = #{id} AND ps.person_id = p.id ' +
      'ORDER BY p.first_name'

I would like to pass in the the id of the object that calls
subscribers.

for instance @email.subscribers could have the association:

has_many :subscribers, :class_name => “Person”, :finder_sql =>
'SELECT DISTINCT people.* ’ +
'FROM people p, post_subscriptions ps ’ +
‘WHERE ps.post_id = #{id} AND ps.person_id = p.id ’ +
’ AND ps.email_id = #{self.id OR @email.id ???}’ +
‘ORDER BY p.first_name’

I did try the above example but it did not work.

Any suggestions?

Roland

oops… I had to use the ‘’ and + to get the id in… Using “” doesn’t
work. I thought it was equivalent but heck… whatever works…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs