#---------------------------------------------------------------
policies = Table('pol_homepolicy_tbl', engine,
Column('pol_policy_num', String(10), primary_key=True, key='policyNum'),
Column('pol_policy_eff_date', DateTime, primary_key=True, key='effectiveDate'),
...
)
endorsements = Table('end_endorsement_tbl', engine,
Column('end_policy_num', String(10), ForeignKey('pol_homepolicy_tbl.policyNum'), primary_key=True, key='policyNum'),
Column('end_policy_eff_date', DateTime, ForeignKey('pol_homepolicy_tbl.effectiveDate'), primary_key=True, key='effectiveDate'),
Column('end_endorsement_type', String(20), ForeignKey('uhe_endorsement_tbl.type'), primary_key=True, key='type'),
Column('end_endorsement_id', Integer, primary_key=True, key='id'),
Column('end_endorsement_desc', String(150), key='description'),
Column('end_endorsement_premium', Numeric(precision=2, length=9), key='premium')
...
)
endorsement_line_items_select = select(
[
endorsements.c.type,
endorsements.c.id,
endorsements.c.description,
endorsements.c.premium
]
).alias('endorsement_line_items_select')
EndorsementLineItem.mapper = mapper(EndorsementLineItem, endorsement_line_items_select)
distinct_endorsements_select = select(
[
endorsements.c.policyNum ,
endorsements.c.effectiveDate,
endorsements.c.type
],
distinct=True
).alias('distinct_endorsements_select')
Endorsement.mapper = mapper(Endorsement, distinct_endorsements_select, is_primary=True, properties=dict(
lineItems = relation(EndorsementLineItem.mapper, lazy=True, private=True,
primaryjoin=distinct_endorsements_select.c.end_endorsement_type==endorsement_line_items_select.c.end_endorsement_type
)
))
Policy.mapper = mapper(Policy, policies, properties=dict(
endorsements = relation(Endorsement.mapper, lazy=True, private=True)
))
policies = Table('pol_homepolicy_tbl', engine,
Column('pol_policy_num', String(10), primary_key=True, key='policyNum'),
Column('pol_policy_eff_date', DateTime, primary_key=True,
key='effectiveDate'),
...
)
endorsements = Table('end_endorsement_tbl', engine,
Column('end_policy_num', String(10),
ForeignKey('pol_homepolicy_tbl.policyNum'), primary_key=True, key='policyNum'),
Column('end_policy_eff_date', DateTime,
ForeignKey('pol_homepolicy_tbl.effectiveDate'), primary_key=True,
key='effectiveDate'),
Column('end_endorsement_type', String(20),
ForeignKey('uhe_endorsement_tbl.type'), primary_key=True, key='type'),
Column('end_endorsement_id', Integer, primary_key=True, key='id'),
Column('end_endorsement_desc', String(150), key='description'),
Column('end_endorsement_premium', Numeric(precision=2, length=9),
key='premium')
...
)
endorsement_line_items_select = select(
[
endorsements.c.type,
endorsements.c.id,
endorsements.c.description,
endorsements.c.premium
]
).alias('endorsement_line_items_select')
EndorsementLineItem.mapper = mapper(EndorsementLineItem,
endorsement_line_items_select)
distinct_endorsements_select = select(
[
endorsements.c.policyNum,
endorsements.c.effectiveDate,
endorsements.c.type
],
distinct=True
).alias('distinct_endorsements_select')
Endorsement.mapper = mapper(Endorsement, distinct_endorsements_select,
is_primary=True, properties=dict(
lineItems = relation(EndorsementLineItem.mapper, lazy=True, private=True,
primaryjoin=distinct_endorsements_select.c.end_endorsement_type==endorsement_line_items_select.c.end_endorsement_type
)
))
Policy.mapper = mapper(Policy, policies, properties=dict(
endorsements = relation(Endorsement.mapper, lazy=True, private=True)
))

