Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda