说我有这些模型
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
这样我才能做到
p = Project.find(1, :include => :comments)
p.comments.collect(&:user).collect(&:name) # this executes select for each user
我怎么说我还要包含评论的用户?
答案 0 :(得分:10)
我相信:include => {:comments => :user}
应该有用。