Re: [sqlalchemy] How to test if an object attribute is a relationship

2018-09-07 Thread Jacek Blocki
Works like a charm and looks much better. > how about, "attr in inspect(obj).mapper.relationships" ? > > > > > > > -- > > SQLAlchemy - > > The Python SQL Toolkit and Object Relational Mapper > > > > http://www.sqlalchemy.org/ > > > > To post example code, please provide an MCVE: Minimal,

Re: [sqlalchemy] How to test if an object attribute is a relationship

2018-09-07 Thread Mike Bayer
On Thu, Sep 6, 2018 at 4:46 PM, Jacek Blocki wrote: > Is there a stock function to test if an object attribute is a relationship? > I have created below function to test it, is there a better solution? > > def is_relationship(obj, attr): > try: > p = inspect(getattr(type(obj), attr)).p

[sqlalchemy] How to test if an object attribute is a relationship

2018-09-06 Thread Jacek Blocki
Is there a stock function to test if an object attribute is a relationship? I have created below function to test it, is there a better solution? def is_relationship(obj, attr): try: p = inspect(getattr(type(obj), attr)).property except (AttributeError, NoInspectionAvailable):