chained_join.py 880 B

12345678910111213141516171819202122232425262728293031
  1. def chained_join(*relationships):
  2. """
  3. Return a chained Join object for given relationships.
  4. """
  5. property_ = relationships[0].property
  6. if property_.secondary is not None:
  7. from_ = property_.secondary.join(
  8. property_.mapper.class_.__table__,
  9. property_.secondaryjoin
  10. )
  11. else:
  12. from_ = property_.mapper.class_.__table__
  13. for relationship in relationships[1:]:
  14. prop = relationship.property
  15. if prop.secondary is not None:
  16. from_ = from_.join(
  17. prop.secondary,
  18. prop.primaryjoin
  19. )
  20. from_ = from_.join(
  21. prop.mapper.class_,
  22. prop.secondaryjoin
  23. )
  24. else:
  25. from_ = from_.join(
  26. prop.mapper.class_,
  27. prop.primaryjoin
  28. )
  29. return from_