Build ActiveRecord models via module inclusion instead of class inheritance.
Since you're only allowed to inherit from a single class, it would be preferable to include ActiveRecord as a module. This allows class inheritance to be used for cases where there's an actually hierarchical relationship.
This gem creates a module named
ActiveRecord::Model that includes all
the same functionality as
ActiveRecord::Base, including everything that
has been mixed into
In your model, just include
class User include ActiveRecord::Model # ... end
This is effectively equivalent to:
class User < ActiveRecord::Base # ... end
Add this line to your application's Gemfile:
And then execute:
- Add some tests. This is pretty simple, but we should test a few things.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request