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

119
Visualizações
Select fields from different tables - TypeORM

I am somewhat new to SQL. I have three tables users_table, products_table, and users_orders. The users_table holds basic information about the user and the users_orders table holds information about the user's orders. Here is a structure of the products_table and users_orders.

N.B

Users can signup and create products to be sold on the platform (like a marketplace).

Product table

id: Int
productName: String
price: Int
...
createdBy: Foreign key to user's table

Users orders table

id: Int
isOrdered: bool // to know if a user ordered a particular item
userId: Foreign key to the user's table
productId: Foreign key to the product table

Problem

In the front-end, I make an API call to grab all products from the database and display them on the main page. I want to be able to know if a user has ordered a particular item, if they have, then based on a boolean check, I can make the order button unclickable. This is to prevent them from ordering a particular item twice. (Business requirements).

Expected Behaviour

I currently use TypeORM to handle my database interaction with Postgres. How do I run the query to get all orders from the products_table alongside users_orders to know which item a user has ordered, so that I have the isOrdered field returned back to me?

API Response Example

When I make a call to the DB to get all products, a response like so is returned.

[
 {
  productName: String
  price: Int
  createdBy: User who created the product listing
  date: Date
 }
]

I want to be able to make a single query that can check the users_orders and products_table to know which product the current loggedIn user has made. So the response could be like this

[
 {
  id: Int
  productName: String
  price: Int
  createdBy: User who created it
  isOrdered: Boolean
  productId: Product object details
 }
]

How do I achieve this with TypeORM? Thank you in advance!

about 4 years ago · Juan Pablo Isaza
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