Recursive: Enable Rails ActiveRecord

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 can I say that I also want to include user comments?

+4
source share
1 answer

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

+10
source

All Articles