我的设置:Rails 3.0.9,Ruby 1.9.2
型号:
class User
has_many :posts
has_many :photos
class Post
belongs_to :user
has_many :comments
class Photo
belongs_to :user
has_many :comments
class Comment
belongs_to :post
belongs_to :photo
在User
级别,我想抓住user.posts
和user.photos
附带的所有评论,是否可能,如果是,那么语法是什么?
答案 0 :(得分:4)
user.posts.map(&:comments)
或user.photos.map(&:comments)