Open simmerer opened 8 years ago
Thanks for the PR! I need to add some additional tests around STI to make sure the change from ActiveRecord::Base.subclasses
to ActiveRecord::Base.descendants
doesn't result in an extra seed file being generated for the base class. If it does, I'll have to handle that case.
Either way -- appreciate this! I'll try to get on the STI thing sometime over the next week.
Backstory
In Rails 5, all models inherit from
ApplicationRecord
, which inherits fromActiveRecord::Base
( https://github.com/rails/rails/pull/22567 ). For instance, my User model:sprig-reap
looks up models viaActiveRecord::Base.subclasses
, which only looks up direct subclasses ofActiveRecord::Base
. As a result,rake db:seed:reap
in Rails 5 fails silently with no records reaped:Reaping from the Rails console shows the error:
Change
Using the
.descendants
method, however, all levels of subclassing can be accessed, and I can successfully reap all of my models.Rather than changing sprig-reap to look up direct subclasses of
ApplicationRecord
, I've modified it to callActiveRecord::Base.descendants
. This should preserve compatibility with pre-Rails-5 models that inherit directly fromActiveRecord:Base
and/or don't inherit fromApplicationRecord
.