开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜