sql - How to check if record does NOT exist in Rails 5 with active record querying? -
i have article model , comments model. how list of articles not have comments using active record?
model columns:
article: body:string (has many comments)
comment: body:string, article_id:integer (belongs article)
if want result using single query , want result activerecord relation, use:
article.where('id not in (select distinct(article_id) comments)')
Comments
Post a Comment