AR Find Trickery

found = ModelA.find_by(id: id) || ModelB.find(id)

I stumbled over this during a code review. It was supposed to look for a record in two distinct tables.

find_by

  will return

nil

  if nothing was found while

find

  will

raise

 . Hence either you get something (from any model) or you

raise

.

Leave a Reply

Your email address will not be published. Required fields are marked *