views:

355

answers:

1

Say I have these models

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

So that I can do

p = Project.find(1, :include => :comments)
p.comments.collect(&:user).collect(&:name) # this executes select for each user

How do I say I want to also include comment's user?

+7  A: 

I believe :include => {:comments => :user} should work.

mrueg