Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.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 ActiveRecord中_Ruby On Rails_Activerecord - Fatal编程技术网

Ruby on rails 递归:包含在Rails ActiveRecord中

Ruby on rails 递归:包含在Rails ActiveRecord中,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,假设我有这些模型 class Project < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :project belongs_to :user end class User < ActiveRecord::Base has_many :comments end 我怎么说我还想包括注释的用户呢?我认为:incl

假设我有这些模型

class Project < ActiveRecord::Base
    has_many :comments
end

class Comment < ActiveRecord::Base
    belongs_to :project
    belongs_to :user
end

class User < ActiveRecord::Base
    has_many :comments
end

我怎么说我还想包括注释的用户呢?

我认为
:include=>{:comments=>:user}
应该可以工作。

如果我已经包括了一些非递归的东西怎么办?我目前有:include=>:items,我需要将它与这样的东西结合起来,:include=>{:other_item=>:items}。可能吗?
p = Project.find(1, :include => :comments)
p.comments.collect(&:user).collect(&:name) # this executes select for each user