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.21k stars 179 forks source link

support `has_many :through` associations #296

Closed flavorjones closed 11 months ago

flavorjones commented 11 months ago

This PR closes #239.

The first commit removes unused (and broken?) code that I found while looking at the association code. It was part of e6a47bcc and should not have been present.

The second commit refactors the extensions spec a bit to minimize the test classes being created for each test; this makes the tests more explicit and speeds them up slightly.

The final commit introduces the test from #239 and overrides the has_many method in any class that includes ActiveHash::Associations::ActiveRecordExtensions. The new implementation will adopt new behavior if the :through option is present and it points at an ActiveHash::Base class:

Otherwise has_many will just call super.