开发者

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 as开发者_C百科sociated with that tables?

Is it possible?

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

Thanks in advance.


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_
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜