I have found the answer to my question, but in the wrong format.
Using SQL Alchemy I want to join columns from Table A to one column on Table B.
Table A contains two columns for Location Code. I can retrieve the Location Name by joining on to Table B, but how to do this?
So far I have this:
locationreq = sa.Table("INMPTL_LOCATION_REQUEST", meta.metadata,
sa.Column("request_id", sa.types.String(), primary_key=True),
sa.Column("status", sa.types.String(100)),
sa.Column("new_loc", sa.types.String(), sa.ForeignKey("INMPTL_LOCATIONS_TBL.inmptl_location_code")),
sa.Column("previous_loc", sa.types.String(), sa.ForeignKey("INMPTL_LOCATIONS_TBL.inmptl_location_code")),
autoload=True,
autoload_with=engine)
locationtable = sa.Table("INMPTL_LOCATIONS_TBL", meta.metadata,
sa.Column("INMPTL_LOCATION_CODE", sa.types.Integer(), primary_key=True),
autoload=True,
autoload_with=engine)
orm.mapper(Location, locationtable )
orm.mapper(LocationRequest, locationreq, extension= wf.WorkflowExtension(), properties = {'location':relation(Location)}
If only one of these columns were mapped to the second table, I could call something such as:
model.LocationRequest.location.location_name
But because I am mapping two columns to the same table, it is getting confused.
Does anyone know the proper way to achieve this?
I was going to delete this question, but this is not a duplicate. The answer is here (setting the primary and secondary joins)