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
The cleanest way without SQL injection vulnerability is using query parameters:
User.joins(:pets).where("pets.name != ?", "fluffy")
Some database drivers will utilize prepared statements for above to reuse database query plan. In such case the database doesn't have to analyze query again when only param value varies.