Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # user.rb
- # simple
- has_many :posts, dependent: :destroy # all posts
- has_many :published_posts, -> { where(published: true) }, class_name: "Post" # all published posts
- # advanced
- has_many :comments, through: :posts, dependent: :destroy
- 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