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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -