Forum: Ruby on Rails :has_many through with owner-dependent conditions

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Steven P. (Guest)
on 2008-10-10 02:22
(Received via mailing list)
I have a situation where I abstractly have a has_many through
relationship between three tables. Without the through, I'd have no
trouble passing the necessary value to the third table, but with it, I
have no access to the original object id.

This is what I've come up with but I'm wondering if there's not
something better (particularly since sql_conditions isn't really part
of the public API.)

  belongs_to :property_type

  has_many :properties,
           :through => :property_type do
    def sql_conditions
      conditions = "properties.integer_value = #{}"
      if base = super
        conditions = "(" + [ conditions, base ].join(")AND(") + ")"
This topic is locked and can not be replied to.