active-hash / active_hash

A readonly ActiveRecord-esque base class that lets you use a hash, a Yaml file or a custom file as the datasource
MIT License
1.2k stars 179 forks source link

Allow #find to behave like Enumerable#find if id is nil and a block is given #183

Closed nsommer closed 4 years ago

nsommer commented 4 years ago

We discovered in our codebase that we often used #find chained after a #where or #all query, which used to invoke Enumerable#find because an Array was returned.

Since those methods are chainable now and return an ActiveHash::Relation, #find calls invoked the implementation in the relation class.

This change makes ActiveHash::Relation#find compatible with both the query variant (find by id) as well as with the Enumerable variant (find by block criteria). This is how active record behaves, too.

ktmouk commented 4 years ago

:+1:

syguer commented 4 years ago

👍