Alex Rivera | Logout

How to avoid ActiveRecord::RecordNotFound exceptions when querying multiple records

Asked 2010-10-18T17:55:31.877
14

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?

Edit
Report

1 Answer

22

Article.find_all_by_id([1,2,3]) is the way to go!

answered 2010-10-18T18:01:46.257

Your Answer