Open AbdealiLoKo opened 2 years ago
Having a parent_table()
function would also be great.
I have created something like this in my own projects:
from sqlalchemy_continuum import versioning_manager, parent_class
def parent_table(table):
if table in versioning_manager.association_version_tables:
parent_table = next(
iter(
t
for t in versioning_manager.association_tables
if versioning_manager.options['table_name'] % t.name == table.name
),
None,
)
return parent_table
parent_table = next(
iter(
parent_class(m).__table__
for m in versioning_manager.version_class_map
if m.__table__ == table
),
None,
)
return parent_table
@marksteward I was hoping to create a PR for this - if there is interest on your side
I can think of 2 approaches here:
VersioningManager.association_tables
-> VersioningManager.parent_association_table_map
and VersioningManager.association_version_tables
-> VersioningManager.version_association_table_map
?I feel solution 2 is a bit better and more consistent with VersioningManager.version_class_map
VersioningManager.parent_class_map
What would you recommend ?
I have been using the variables:
parent_class_map
version_class_map
association_tables
association_version_tables
A lot. And they helps me to use sqla-continuum effectively for various logic I need for my application.
But recently I came across a case where I was doing:
But with sqla-continuum, I wanted to be able to change it to:
I couldn't find any good way to figure out this mapping