File: chained_join.py

package info (click to toggle)
python-sqlalchemy-utils 0.30.12-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,056 kB
  • sloc: python: 10,350; makefile: 160
file content (31 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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_