Display Users without Posts in Rails -
how query users have yet write posts? trying:
u = user.joins(:posts).where('posts.size = ?', 0)
output:
pg::undefinedcolumn: error: column posts.size not exist
trying wrap head around correct sql syntax, no luck far
you must without join, this:
user.where(post.where("posts.user_id = users.id").exists.not)
its useful chain conditions (like applying different filters).
creates sql like:
select "users".* "users" ( not ( exists (select "posts".* "posts" (posts.user_id = users.id)) ) )
Comments
Post a Comment