Get reference count of reverse foreign key relations
I don't know postgres well, but I am not aware of any way to do this in a single query. I also doubt there'll be a truly portable way, but the approach is similar.

Generally, I think you'd need to:


Query system (meta) tables to find all foreign key table and column names.
Use this to generate a (possibly massive) select query that counts all the 12s