I have this code:
Article.find([1,2,3])
But only record 1 and 2 exist in the database. I get this exception:
"ActiveRecord::RecordNotFound (Couldn't find all Offers with IDs (1,2,3) (found 2 results, but was looking for 3))"
Is there a way to only get the existing records and not the exception?
Article.find_all_by_id([1,2,3])
is the way to go!
Rails 3+, ruby 1.9+ way:
Article.where(id: [1,2,3])
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