Good Day
I have to tables: tblAssets & tblAssetTypes. tblAssets is the main table and contains a column assetType that is an integer and is linked to tblAssetTypes id column. I have defined the models as follows:
class Assets(Base):
__tablename__ = "tblAssets"
id = Column(Integer, primary_key=True, index=True)
assetName = Column(String)
assetType = Column(Integer, ForeignKey("tblAssetTypes.id"))
assetCategory = Column(Integer)
assetSerial = Column(String(50), unique=True, index=True)
assetLabel = Column(String(50), unique=True, index=True)
assetUser = Column(Integer)
primaryLocation = Column(String)
secondaryLocation = Column(String)
assetStatus = Column(String)
assetValue = Column(Float)
assetCondition = Column(Integer)
assetQuantity = Column(Integer)
two = relationship("AssetTypes", back_populates="one")
class AssetTypes(Base):
__tablename__ = "tblAssetTypes"
id = Column(Integer, primary_key=True, index=True)
assetType = Column(String)
one = relationship("Assets", back_populates="two")
Currently, I am receiving results as follows:
[
{
"id": 1,
"assetType": 1,
"assetSerial": "SERIAL",
"assetUser": 1,
"primaryLocation": "South Afric",
"assetStatus": "A",
"assetCondition": 10,
"assetCategory": 1,
"assetName": "Apple MacBook Pro 13 inch",
"assetLabel": "MP-SA-LP-01",
"secondaryLocation": "ASF",
"assetValue": 30000,
"assetQuantity": 1
}
]
I would like to do an "inner join" where it replaces the assetType id with the assetType name.
I have tried checking other StackOverflow questions for a solution but I was not able to find a solution to my issue.
Any help with this would be appreciated and if I haven't provided enough information, I am more than willing to provide more.