Reputation: 702
I have a model Service
with has_and_belongs_to_many
relationship to a Languages
model.
I would like to get a scope of all the services that have a given language.
I have tried
Service.joins(:languages).where(:languages => Language.find(1))
but get Mysql2::Error: Unknown column 'services.language_id'
as its using a 3rd table to create the association.
Now im stuck, any pointers please wonderful people?
Upvotes: 0
Views: 82
Reputation: 2072
This must be the answer
@language = Language.find_by_id(1)
@services = @language.services
Then run loop.
Upvotes: 1