Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Adding parent_table_map/version_table_map #286

Open
AbdealiLoKo opened this issue Aug 22, 2022 · 2 comments
Open

Suggestion: Adding parent_table_map/version_table_map #286

AbdealiLoKo opened this issue Aug 22, 2022 · 2 comments

Comments

@AbdealiLoKo
Copy link
Contributor

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:

isinstance(mytable, MyMixinClass)

But with sqla-continuum, I wanted to be able to change it to:

isinstance(mytable, MyMixinClass)
    or (
        mytable in versioning_manager.association_version_tables
        and isinstance(parent_table(mytable), MyMixinClass
    )

I couldn't find any good way to figure out this mapping

@AbdealiLoKo
Copy link
Contributor Author

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

@AbdealiLoKo
Copy link
Contributor Author

AbdealiLoKo commented Aug 26, 2022

@marksteward I was hoping to create a PR for this - if there is interest on your side

I can think of 2 approaches here:

  1. Create a helper utils.parent_table() which uses the logic I wrote above
  2. Change the current 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 ?

indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Sep 11, 2022
indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Sep 11, 2022
indiVar0508 added a commit to indiVar0508/sqlalchemy-continuum that referenced this issue Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants