开发者

Nested AREL queries in Rails

开发者 https://www.devze.com 2023-03-20 08:21 出处:网络
Simple question with a couple of simple models: class Contract < ActiveRecord::Base belongs_to :property

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

精彩评论

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

关注公众号