Nested AREL queries in Rails
Simple question with a couple of simple models:
class Contract < ActiveRecord::Base
belongs_to :property
end
class Payment < ActiveRecord::Base
has_one :contract
end
How can I write a where clause that retrieves all the payments associated with a set of properties?
Something li开发者_C百科ke:
scope :for_properties, lambda { |property_ids| joins(:contract).where(:contracts => { :property_id => property_ids})
but that doesn't quite work. Anyone have a lot of AREL foo?
精彩评论