What I'd like to do is count all objects in the database. I started with something like this:
p ["TOTAL COUNT", ApplicationRecord.subclasses.sum(&:count)]
But while experimenting I found...
[5] pry(main)> ApplicationRecord.subclasses.count => 6
Which I expected to return a lot more than that. I can inspect the subclasses and find that some are missing.
Then I found....
[8] pry(main)> ActiveRecord::Base.descendants.count => 10
Which added a few more. Again I can inspect them individually, and I noticed a few were missing. Here is an example of one that is missing...
class MerchantsPrincipal < ApplicationRecord
end
class Principal < MerchantsPrincipal
end
How can I make sure those are also included?
MerchantsPrincipal.countalready includesPrincipal.countbecause of how STI works sodescendantsis not what you're looking for.