Mirror318
Mirror318

Reputation: 12663

Rails—count of all records in db?

I have a very snowballing program that creates a whole heap of records (from different models).

I want to delete the main record, and make sure all the other records associated have also been deleted.

Is there a way to simply count all records in my DB, regardless of what table? Then I can create everything, trigger the main delete, then check if there's anything left in the DB.

Upvotes: 1

Views: 1026

Answers (1)

Mori
Mori

Reputation: 27779

Rails.application.eager_load!
ActiveRecord::Base.subclasses.sum(&:count)

Upvotes: 4

Related Questions