Many to Many with Multiple Parents in SQLAlchemy
I'm not sure the title is correct so let me give an example
Say I have TableA and TableB classes, and a History class.
History would just be id, attribute, old value, new value.
Each Table would have a many-many relationship with History.
Obviously I can create a tablea_history and tableb_history table to keep
track of the relationships.
However I'm going to have 5-10 TableA/B type tables and 3-4 History type
tables so that adds up to quite a bit of simple relationship tables. Is
that okay? (In both management and efficiency?) It seems like that would
add a lot of extra code.
I could also have a History defined by id, table_name, attribute, old, new
but then I wouldn't know how create nice SQLAlchemy relationships.
TL;DR
I guess I am asking what is the best way to associate a child table to
multiple kinds (different classes) of parent tables that lets me not worry
about the behind the scenes stuff and just use nice SQLalchemy
relationships.
No comments:
Post a Comment