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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -