Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails连接重复默认的\u范围_Ruby On Rails_Ruby On Rails 4_Default Scope - Fatal编程技术网

Ruby on rails Rails连接重复默认的\u范围

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

经过进一步的调查,这个错误似乎是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: 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')