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,
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
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):