0

I have one single master Subject table which have several part tables. One convenient thing about Table.delete() is that is displays a prompt with all existing entries that were created under that Subject. Aside from delete() is there an alternative way to print what part table entries were created under a single Subject entry?

Thank you

Sahil
  • 5
  • 2
  • 1
    Still thinking through the best answer here, but it may involve `subject.Subject.descendants()`, which will give you the backend name convention for all tables related to the one you've picked. Maybe theres a way to go from that list to the set of entries you're interested in... – Chris Broz Jun 01 '22 at 17:17

2 Answers2

1

To get the entry count of all the part tables restricted by some restriction (e.g. subject_name), you can do something like this:

restriction = {'subject_name': 'my_star_subject'}

for part_table in Subject.parts(as_objects=True):
    part_table_query = part_table & restriction
    print(f'{part_table.table_name}: len(part_table_query)')
0

It's a slow process, but I think I would do the following to see where entries were:

(subject.Subject & 'subject="<NAME>"').descendants(as_objects=True)

Not sure if you'd be better off with children (1 level down) or descendants (all the way down). delete gives the full set of descendants, using table.delete_quick(get_count=True).

EDIT: To just get the counts, you might want:

[print(i.table_name,len(i)) for i in (subject.Subject & 'subject="<NAME>"').descendants(as_objects=True)]
Chris Broz
  • 136
  • 8