Skip to content

Suggestion: Adding parent_table_map/version_table_map #286

Closed as not planned

Description

@AbdealiLoKo

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

Activity

  1. AbdealiLoKo commented on Aug 22, 2022

    @AbdealiLoKo
    ContributorAuthor

    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
  2. AbdealiLoKo commented on Aug 26, 2022

    @AbdealiLoKo
    ContributorAuthor

    @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 ?

  3. added 3 commits that reference this issue on Sep 11, 2022
  4. josecsotomorales commented on Oct 15, 2026

    @josecsotomorales
    Collaborator

    The manager already exposes association_tables and association_version_tables, and sqlalchemy_continuum.utils.version_table() maps a table to its version table, so the reverse is a short lookup like the one you wrote. We're not adding more registry maps for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions