How to find sqlalchemy remote side object's class or class name without db queries?

Viewed 5468

Let's have a classes X and Y and relations between them x2y and y2x. From class_mapper(Class).iterate_properties iterator we can get all class's properties. So x2y and y2x are RelationshipProperty and what I hope to get from is a class or a class name of objects on remote side of relation.

I've already tried to make a solution. I've found x2y.remote_side[0].table.name, made a tables_map which maps a table name to a class and it works fine for one-to-many and one-to-one. If I use it for many-to-many the table name is an association table.

Any hints on how can I get the remote side class?

2 Answers
Related