teksi / wastewater

[DEV] Future TEKSI wastewater module, adapted data model to fit VSA-DSS 2020 new standard
https://teksi.github.io/wastewater
GNU General Public License v3.0
2 stars 5 forks source link

Improvement INTERLIS export (selection) #280

Open sjib opened 4 months ago

sjib commented 4 months ago

Add missing re_tables in configuration (database tables exist already)

sjib commented 4 months ago

export selection dss: what to do here? gesamteinzugsgebiet.fk_einleitstelle is MANDATORY, but this Einleitstelle might not be in selection

sjib commented 4 months ago
sjib commented 4 months ago

Currentyl: query = query.filter( self.model_classes_tww_od.param_ca_general.objid.in(self.subset_ids)

query = query.filter( self.model_classes_tww_od.param_ca_mouse1.objid.in(self.subset_ids)

Tried version: https://github.com/teksi/wastewater/pull/266#issuecomment-2207063078

        query = query.join(
            self.model_classes_tww_od.catchment_area,
            self.model_classes_tww_od.wastewater_networkelement,
            or_(
                self.model_classes_tww_od.wastewater_networkelement.obj_id
                == self.model_classes_tww_od.catchment_area.fk_wastewater_networkelement_rw_planned,
                self.model_classes_tww_od.wastewater_networkelement.obj_id
                == self.model_classes_tww_od.catchment_area.fk_wastewater_networkelement_rw_current,
                self.model_classes_tww_od.wastewater_networkelement.obj_id
                == self.model_classes_tww_od.catchment_area.fk_wastewater_networkelement_ww_planned,
                self.model_classes_tww_od.wastewater_networkelement.obj_id
                == self.model_classes_tww_od.catchment_area.fk_wastewater_networkelement_ww_current,
            ),
        ).filter(
            self.model_classes_tww_od.wastewater_networkelement.obj_id.in_(self.subset_ids)
        )

E sqlalchemy.exc.AmbiguousForeignKeysError: Can't determine join between 'Join object on Join object on surface_runoff_parameters(139990536639488) and param_ca_general(139990536638672)(139990553374128) and catchment_area(139990536642368)' and 'wastewater_networkelement'; tables have more than one foreign key constraint relationship between them. Please specify the 'onclause' of this join explicitly.

sjib commented 4 months ago

Test if filter with union work better using this structure:

union: q3 = q1.union(q2) instead of query = query.union(query1, query2) see https://docs.sqlalchemy.org/en/14/orm/query.html#sqlalchemy.orm.Query.union