I have a Post
model that has many comments
class Post < ApplicationRecord
has_many :comments
end
How do I get distinct posts that have comments excluding the posts that do not have comments?
I believe that Post.joins(:comments).distinct("posts.*")
does the job.
Is there any better alternative?
I emphasize that the result…
</p>
?signin=true
Top comments (0)