Files
zenml/venv/lib/python3.9/site-packages/sqlalchemy_utils/relationships/chained_join.py
Christian Mantha 2ca0b9ef7c star
2026-03-02 19:10:52 -05:00

22 lines
730 B
Python

def chained_join(*relationships):
"""
Return a chained Join object for given relationships.
"""
property_ = relationships[0].property
if property_.secondary is not None:
from_ = property_.secondary.join(
property_.mapper.class_.__table__, property_.secondaryjoin
)
else:
from_ = property_.mapper.class_.__table__
for relationship in relationships[1:]:
prop = relationship.property
if prop.secondary is not None:
from_ = from_.join(prop.secondary, prop.primaryjoin)
from_ = from_.join(prop.mapper.class_, prop.secondaryjoin)
else:
from_ = from_.join(prop.mapper.class_, prop.primaryjoin)
return from_