Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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 命名空间模型上的ActiveRecord查询方法_Ruby On Rails_Ruby_Activerecord - Fatal编程技术网

Ruby on rails 命名空间模型上的ActiveRecord查询方法

Ruby on rails 命名空间模型上的ActiveRecord查询方法,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,我有一组常见的模型,它们被提取到一个gem中,并具有名称空间模型: module Gemifive class Activity < ActiveRecord::Base belongs_to :user end class User < ActiveRecord::Base has_many :activities end end 但是,以下不起作用:gemive::Activity.where(user:user)。这将生成以下SQL,该SQL

我有一组常见的模型,它们被提取到一个gem中,并具有名称空间模型:

module Gemifive
  class Activity < ActiveRecord::Base
    belongs_to :user
  end

  class User < ActiveRecord::Base
    has_many :activities
  end
end
但是,以下不起作用:
gemive::Activity.where(user:user)
。这将生成以下SQL,该SQL无效:

SELECT "gemifive_activities".* FROM "gemifive_activities" WHERE "gemifive_activities"."user" = 18
我可以访问
gemive::Activity.first.user
很好,所以我知道
所属的关联正在工作。为什么我不能使用这个ActiveRecord约定

Gemifive::Activity.where(user: user)
这是无效的ARel,简单明了。这与模型的名称空间无关。在上面的代码中,ARel使用散列的键作为列名,并且将逐字使用。你能做的就是


在失败的情况下,您使用什么代码设置
user
的值?您知道吗,您是对的。我不知道为什么我希望这能奏效,我可能是疯了。我一定被
Order.create(user:some\u user)
之类的东西弄糊涂了,因为AR在INSERT语句中将
user
键转换为
user\u id
Gemifive::Activity.where(user: user)
Gemifive::Activity.where(user_id: user)