ruby on rails - active record query with `where` and `not in` -
i'm trying retrieve users 2 conditions. profile_type must "patient" , not in blacklisted_ids
blacklisted_ids = [1, 2, 3] user.where(profile_type: "patient", id: not_in blacklisted_ids) the following works i'd 1 query , not chain. there many examples of where , where.not none in single query.
user.where(profile_type: 'patient').where.not(id: blacklisted_ids)
chained criteria (in case) 1 query. translates 1 sql statement. if want syntactically express in 1 wrapped clause best is
user.where("profile_type = 'patient' , id not in (?)", blacklisted_ids)
Comments
Post a Comment