sql - Check if record does NOT exist in Rails (from array of ids)? -
i can check if record(s) exists (say id "1" exists, "2" , "3" don't):
model.exists?(:id => [1, 2, 3]) #=> true
how do opposite, so:
model.not_exists?(:id => [1, 2, 3]) #=> true
if need search records through id can try this
class model def self.not_exists?(ids) self.find(ids) false rescue true end end
if of ids not exist find
method raise activerecord::recordnotfound exception catch , return true.
excuse english :)
Comments
Post a Comment