Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda