I have a number of models
class User < ActiveRecord::Base
belongs_to :group
end
class Group < ActiveRecord::Base
has_many :users
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :group
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
To get a user's post I can do User.find(1).group.posts.all
, but if I want all comments for a user's posts I can't do User.find(1).group.posts.all.comments.all
.
Is there an easy solution to get all comments for a user's posts other than looping through all the posts?