Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. # user.rb
  2. # simple
  3. has_many :posts, dependent: :destroy # all posts
  4. has_many :published_posts, -> { where(published: true) }, class_name: "Post" # all published posts
  5.  
  6. # advanced
  7. has_many :comments, through: :posts, dependent: :destroy
  8. has_many :comments_on_published_posts, through: :published_posts, dependent: :destroy # comments on published posts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement