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

Scopes are not chainable #247

Closed andreynering closed 2 years ago

andreynering commented 2 years ago

Hey there!

Thanks for this project! We use it extensively at JobScore and love it.

I'd like to request something, though. Scopes work in isolation, but you can't use more than one together, which works in ActiveRecord and is extremely convenient. Could this possibly be implemented?

class Vehicle
  scope :car, -> { where(type: 'car' }
  scope :motorized, -> { where(motorized: true}
end
> Vehicle.car.motorized
NoMethodError: undefined method `motorized' for #<ActiveHash::Relation:0x000000010732d9c8>
andreynering commented 2 years ago

I just gave it a try at https://github.com/active-hash/active_hash/pull/248