Ruby on Rails ActiveRecord query using a join
This should work:
User.joins(:pets).where("pets.name != 'fluffy'")
Also you might want to read the following part (on joins
) on the official RoR guidelines.
In rails 4 you can make this even more clear:
User.joins(:pets).where.not(pets: { name: 'fluffy' })