1
class Property < ActiveRecord::Base
  has_many :units

  def self.default_scope
    where('active_at <= :now AND inactive_at > :now', now: Time.zone.now)
  end
end

class Unit < ActiveRecord::Base
  belongs_to :property

  def self.with_active_properties
   joins(:property)
  end
end

Rails 4.0.2 の default_scope を join で使用しようとしていますが、呼び出すとUnit.with_active_properties次のような SQL が重複して表示されるのはなぜですか?

SELECT "units".* FROM "units" INNER JOIN "properties" ON "properties"."id" = "units"."property_id" AND (active_at <= '2014-03-11 03:36:13.994068' AND inactive_at > '2014-03-11 03:36:13.994068') AND (active_at <= '2014-03-11 03:36:13.967550' AND inactive_at > '2014-03-11 03:36:13.967550')
4

1 に答える 1