liveh2o / active_remote

Active Remote provides Active Record-like object-relational mapping over RPC. It's Active Record for your platform.
MIT License
63 stars 23 forks source link

Add `find_by` to the Search module #83

Open moveson opened 4 years ago

moveson commented 4 years ago

Currently we have .search, which returns a (possibly empty) array of results, and we have .find, which returns a single result or raises ActiveRemote::RemoteRecordNotFound.

We see a common pattern when we know we need only one record, but we want nil instead of raising an error:

RemoteModel.search(:key => value).first

This MR proposes adding a .find_by method to ActiveRemote classes, which would allow us to instead write:

RemoteModel.find_by(:key => value)

The new method would be parallel to the ActiveRecord .find_by method.