I just discovered answer for myself: from sqlalchemy.orm.properties import RelationProperty from sqlalchemy.orm import class_mapper
def foo(entity_class, collection_property): rel_prop = class_mapper(entity_class, compile=False).get_property (collection_property) related_entity_class = rel_prop.backref.prop.parent.class_ # equals to <class Sea> backref_attr = rel_prop.backref.key # equals to 'ocean' Cool! On Aug 4, 10:31 pm, "nail.xx" <nail...@gmail.com> wrote: > Hi all! > > I have following model classes: > > Entity = sqlalchemy.ext.declarative.declarative_base(name='Entity') > class Ocean(Entity): > __tablename__ = 'oceans' > id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True) > name = sqlalchemy.Column(sqlalchemy.String(20), nullable=False) > class Sea(Entity): > __tablename__ = 'seas' > id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True) > name = sqlalchemy.Column(sqlalchemy.String(20), nullable=False) > ocean_id = sqlalchemy.Column(sqlalchemy.String(20), > sqlalchemy.ForeignKey(Ocean.id)) > ocean = sqlalchemy.orm.relation(Ocean, backref='seas') > > So instances of Ocean have seas property. The question is, if I have a > function: > > def foo(entity_class, collection_property): > # ... > > that is called width args entity_class=Ocean, > collection_property='seas' could I anyhow to understand from within > this function that 'seas' is assotiated with Sea class and that > Sea.ocean is used to bind a Sea to the Ocean? > > Is it ever possible? Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---