from sqlalchemy.orm import aliased
table_event_catalog_1 = aliased(models.EventCatalog)
table_event_catalog_2 = aliased(models.EventCatalog)
table_event_catalog_3 = aliased(models.EventCatalog)
stmt = select(
models.Event,
models.Actor,
models.Place,
models.DataSource,
models.EventType,
models.Region,
table_event_catalog_1,
table_event_catalog_2,
table_event_catalog_3,
models.Calendar,
models.EventSource,
).select_from(models.Event)
stmt = (
stmt.join(models.EventCalendarR)
.join(models.Calendar)
.join(models.EventActorR)
.join(models.Actor)
.join(models.EventPlaceR, isouter=True)
.join(models.Place, isouter=True)
.join(models.DataSource, isouter=True)
.join(models.EventType, isouter=True)
.join(models.Region, isouter=True)
.join(models.EventSource)
.join(
table_event_catalog_1,
table_event_catalog_1.event_catalog_id == models.Event.event_catalog_1,
isouter=True,
)
.join(
table_event_catalog_2,
table_event_catalog_2.event_catalog_id == models.Event.event_catalog_2,
isouter=True,
)
.join(
table_event_catalog_3,
table_event_catalog_3.event_catalog_id == models.Event.event_catalog_3,
isouter=True,
)
.filter(and_(True, *expressions))
)
results = db_session.execute(stmt).all()