[Sqlalchemy-tickets] Issue #3486: Property all_orm_descriptors doesn't contain backref attributes (
Brought to you by:
zzzeek
From: Konsta V. <iss...@bi...> - 2015-07-15 06:11:43
|
New issue 3486: Property all_orm_descriptors doesn't contain backref attributes https://bitbucket.org/zzzeek/sqlalchemy/issues/3486/property-all_orm_descriptors-doesnt Konsta Vesterinen: I don't know if its desired behaviour but currently the `Mapper.all_orm_descriptors` doesn't contain relationship backref attributes. Atleast I think the docs should clearly state that `all_orm_descriptors` doesn't contain these. Consider the following model definition: ```python import sqlalchemy as sa Base = sa.ext.declarative.declarative_base() group_user = sa.Table( 'group_user', Base.metadata, sa.Column('user_id', sa.Integer, sa.ForeignKey('user.id')), sa.Column('group_id', sa.Integer, sa.ForeignKey('group.id')) ) class Group(Base): __tablename__ = 'group' id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(sa.String) class User(Base): __tablename__ = 'user' id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(sa.String) groups = sa.orm.relationship( 'Group', secondary=group_user, backref='users' ) ``` ```python User.__mapper__.attrs.keys() # ['groups', 'id', 'name'] Group.__mapper__.attrs.keys() # ['users', 'id', 'name'] User.__mapper__.all_orm_descriptors.keys() # ['groups', 'id', 'name', '__mapper__'] Group.__mapper__.all_orm_descriptors.keys() # ['id', 'name', '__mapper__'] <- Doesn't contain 'users' ``` I have some situations where I need to inspect all model descriptors. Currently I need to use all_orm_descriptors and combine those with backref relationships of given model. |