Search code examples
ruby-on-railsrubyactiverecordmonologue

How to use where.not with Monologue gem's tagging reference


I'm using the Monologue gem for blogging on my rails 4.0.4 app. I need to find all the posts that don't have a specific tag. The following attempts at trying to do this are not working:

Monologue::Post.includes(:taggings).references(:taggings).where.not(taggings: { tag_id: 1 })

I get what looks to be the proper query but about halfway down it shows:

SQLite3::SQLException: no such column: taggings.tag_id: SELECT "monologue_posts"

What am I doing wrong??


Solution

  • Looks like the table name is monologue_taggings not taggings.

    Try this?

    Monologue::Post.includes(:taggings)
                   .references(:taggings)
                   .where.not(monologue_taggings: { tag_id: 1 })