struct T_AssetTransitCircuit {
1. asset_id
2. vendor_id
3. vendor
}
struct T_AssetTransportCircuit {
1. asset_id
2. vendor_id
3. vendor
}
struct T_Vendor {
1: i32 id,
2: optional string name,
3: optional string sf_id,
4: optional string transit_as_id,
5: optional i64 created_by,
6: optional i64 created_at,
7: optional i64 updated_by,
8: optional i64 updated_at,
9: optional bool active
}
struct T_Circuit {
1. asset_id
2. vendor_id
3. vendor
}
class Vendor:
__tablename__ = 'vendor'
id = Column(DBT.UNSIGNED_INT10, primary_key=True, autoincrement=True)
name = Column(DBT.STRING)
sf_id = Column(DBT.STRING, unique=True, nullable=False)
transit_as_id = Column(DBT.STRING)
created_by = Column(mysql.BIGINT(20))
created_at = Column(NumericDatetime, default=current_timestamp)
updated_by = Column(mysql.BIGINT(20))
updated_at = Column(
NumericDatetime,
nullable=False,
default=current_timestamp,
onupdate=current_timestamp)
active = Column(DBT.UNSIGNED_SMALLINT, nullable=False, default=1)
vendor_mapper = mapper(
T_Vendor,
Vendor.__table__,
)
class AssetTransitCircuit:
__tablename__ = 'asset_transit_circuit'
id = Column(
DBT.UNSIGNED_INT_ID,
ForeignKey("fb_asset.id"),
primary_key=True,
)
vendor_id = Column(DBT.UNSIGNED_INT10, ForeignKey("vendor.id"))
class AssetTransportCircuit:
__table__ = 'asset_transport_circuit'
id = Column(
DBT.UNSIGNED_INT_ID,
ForeignKey("fb_asset.id"),
primary_key=True,
)
vendor_id = Column(DBT.UNSIGNED_INT10, ForeignKey("vendor.id"))
c1_select = select([
AssetTransportCircuit.id,
AssetTransportCircuit.vendor_id,
])
c2_select = select([
AssetTransitCircuit.id,
AssetTransitCircuit.vendor_id,
])
c1_mapper = mapper(
TCircuit,
c1_select,
primary_key=[c1_select.c.id],
properties={
'asset_id': c1_select.c.id,
'vendor_id': c1_select.c.vendor_id,
'vendor': relationship(
vendor_mapper,
foreign_keys=[c1_select.c.vendor_id],
),
)
c2_mapper = mapper(
TCircuit,
c2_select,
primary_key=[c2_select.c.id],
properties={
'asset_id': c2_select.c.id,
'vendor_id': c2_select.c.vendor_id,
'vendor': relationship(
vendor_mapper,
foreign_keys=[c2_select.c.vendor_id],
),
)
q1
=
session.query(c1.mapper._class).options(joinedload('vendor')).options(load_load('id'))
q2
=
session.query(c2.mapper._class).options(joinedload('vendor')).options(load_load('id'))
q1.union(q2).all()
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.