File: chained_join.py

package info (click to toggle)
python-sqlalchemy-utils 0.42.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,236 kB
  • sloc: python: 13,002; makefile: 20
file content (21 lines) | stat: -rw-r--r-- 730 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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_