Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
FastAPI relationship two tables

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.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!