Ruby on Rails ActiveRecord query using a join

前端 未结 3 852
独厮守ぢ
独厮守ぢ 2020-12-28 12:15

I have a User model and the user has a relationship which is has_many pets. I want to be able to write an ActiveRecord query where I can select all users with a pet that doe

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 13:02

    In rails 4 you can make this even more clear:

    User.joins(:pets).where.not(pets: { name: 'fluffy' })
    

提交回复
热议问题