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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edit: Please don’t use this method. Even if it works it’s not optimal since it loads all records instead of only testing their existence. This is a better way of doing it.
If you only need search records through ID you can try this
If any of the IDs does not exist the
findmethod will raise a ActiveRecord::RecordNotFound exception that we simply catch and return true.