Reputation: 290
I have two models 'Article' and 'List' both associated with HABTM association. I also have 'articles_lists' join table that has 'article_id' and 'list_id'. Now I would like to display all the articles that are not associated with any lists. Which is articles which does not have entry in 'articles_lists' table.
How can I achieve this in Rails 5. Please help
Upvotes: 0
Views: 165
Reputation: 6253
you can use
Article.includes(:articles_lists).where( :articles_lists => { :article_id => nil })
Upvotes: 2