When I have an array of identifiers like
ids = [2,3,5]
and I perform
Comment.find(ids)
everything is working fine. But when there is an id that does not exist, I get an exception. This happens in general when I get a list of identifiers that match some filter, and with what I do something like
current_user.comments.find(ids)
This time, I may have a valid comment identifier, which, however, does not belong to this user, so it is not found, and I get an exception.
I tried find(:all, ids), but it returns all records.
The only way to do it now is
current_user.comments.select { |c| ids.include?(c.id) }
But that seems like a super-inefficient solution to me.
Is there a better way to select an ID in an array without getting an exception from a nonexistent record?