andmart
andmart

Reputation: 552

Sqlalchemy: get python class from sqlalchemy.schema.MetaData

I'm trying to prepopulate lists of objects associateds. So for a specific mapped class, I list all tables with :

ExampleClass is my mapped python class, for example.

name = ExampleClass.__name__
tables = [x for x in ExampleClass.metadata.tables.keys() if x != name ]

So, I got the tables name but how can I get the class associated with that tables?

Is it possible?

I'm using the declarative way to map the table and class.

Thanks in advance.

Upvotes: 2

Views: 897

Answers (1)

andmart
andmart

Reputation: 552

I found this way passing the table name param found in list tables

def __find_class(self, table):
        for x in mapperlib._mapper_registry.items():
            if x[0].mapped_table.name == table:
                return x[0].class_

Upvotes: 1

Related Questions