# :has\_many through with owner-dependent conditions

**URL:** <https://www.ruby-forum.com/t/has-many-through-with-owner-dependent-conditions/150566>\
**Category:** Rails\
**Created:** [October 10, 2008, 12:22am UTC](https://www.ruby-forum.com/t/has-many-through-with-owner-dependent-conditions/150566 "2008-10-10T00:22:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thegoatboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9fc348/32.png) [@thegoatboy](https://www.ruby-forum.com/u/thegoatboy)\
**Post date:** [October 10, 2008, 12:22am UTC](https://www.ruby-forum.com/t/has-many-through-with-owner-dependent-conditions/150566/1 "2008-10-10T00:22:38Z")

</div>

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 = #{@owner.id}”  
if base = super  
conditions = “(” + [conditions, base].join(")AND(") + “)”  
end  
conditions  
end  
end
