I have the following associations...
class Event < ActiveRecord::Base
...
has_many :tags, :through => :taggings
This allows me to do something like Event.last.tags and see all tags associated with an email. I'm trying to come up with a where clause for tags where I can do something like...
Event.where tag: 'my_tag'
When I do this I get:
2.1.3 :020 > Event.where tags: 'test'
Event Load (0.4ms) SELECT `events`.* FROM `events` WHERE `events`.`tags` = 'test'
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'events.tags' in 'where clause': SELECT `events`.* FROM `events` WHERE `events`.`tags` = 'test'
Is this what you're looking for?:
Event.includes(:tags).where(tags: {name: 'my_tag'})
This will get all events with tags where tags' name is 'my_tag'. Change name with the appropriate column name which exists in tags table for which you're trying to run query for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With