Im looking to query all Users without Comments in a single sql query?
Models:
class User < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :user
end
So I want the opposite of this:
User.joins(:comments).group('users.id')
But not like this: (because it generates two queries)
User.where.not(id: Comment.pluck(:user_id))
Maybe something like this?
User.joins.not(:comments).group('users.id')
Thanks for any input!