Ruby on rails Rails连接重复默认的\u范围
经过进一步的调查,这个错误似乎是rails 4.0.x中的一个bug导致默认的_范围被调用了两次。我在github上发布了这个问题: 拉里·里德(Larry Reid)在这个问题上的出色帮助值得称赞Ruby on rails Rails连接重复默认的\u范围,ruby-on-rails,ruby-on-rails-4,default-scope,Ruby On Rails,Ruby On Rails 4,Default Scope,经过进一步的调查,这个错误似乎是rails 4.0.x中的一个bug导致默认的_范围被调用了两次。我在github上发布了这个问题: 拉里·里德(Larry Reid)在这个问题上的出色帮助值得称赞 class Property < ActiveRecord::Base has_many :units def self.default_scope where('active_at <= :now AND inactive_at > :now', now: T
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
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')