I can do this to check if a record(s) exists (say id "1" exists, but "2" and "3" don't):
Model.exists?(:id => [1, 2, 3]) #=> true
How do I do the opposite, so:
Model.not_exists?(:id => [1, 2, 3]) #=> true
just add a ! operator
!Model.exists?(:id => [1, 2, 3]) #=> true
If you only need search records through ID you can try this
class Model def self.not_exists?(ids) self.find(ids) false rescue true end end
If any of the IDs does not exist the find
method will raise a ActiveRecord::RecordNotFound exception that we simply catch and return true.
Excuse my English :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With