join

 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
class Nis(RestView):
""" 5.2 Накопительно-ипотечная система (ЦЖЗ)
"""
join = outerjoin(m.Citizens,
m.Documents,
m.Citizens.id == m.Documents.citizen_id).\
outerjoin(m.Certificate, m.ParticipantNis.id == m.Certificate.participant_nis_id).\
outerjoin(m.PurchaseDwelling, m.ParticipantNis.id == m.PurchaseDwelling.participant_nis_id)
query = select([m.Citizens,
m.ParticipantNis,
m.Documents,
m.Certificate,
m.PurchaseDwelling,
m.MilitaryUnits.number,
m.MilitaryUnits.subordination_id],
group_by=m.Citizens.id). \
select_from(join).where(
and_(
or_(
m.Citizens.citizen_id == None,
m.Citizens.citizen_id == 0,
),
m.ParticipantNis.citizen_id == m.Citizens.id,
m.Citizens.military_unit_id == m.MilitaryUnits.id
)
).distinct(m.Citizens.id).apply_labels()