开发者

Rails 3 getting nested records

My setup: Rails 3.0.9, Ruby 1.9.2

Models:

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

At the User level, I would like to grab all the comments attached to user.posts and user.photos, is that possible and if so, what's the syntax?


user.posts.map(&:comments) or user.photos.map(&:comments)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜