开发者

Rails 3 getting nested records

开发者 https://www.devze.com 2023-04-02 01:38 出处:网络
My setup: Rails 3.0.9, Ruby 1.9.2 Models: class User has_many :posts开发者_运维知识库 has_many :photos

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

精彩评论

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