Answer the question
In order to leave comments, you need to log in
What is the best way to sort posts in Rails?
How can a scope be written to sort users who have created posts?
user has_many :posts
post belongs_to :user
Answer the question
In order to leave comments, you need to log in
scope :with_posts, -> { where('EXISTS (SELECT 1 FROM posts WHERE users.id = posts.user_id)') }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question