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

136
Visualizações
Query an entity with an array property containing values from another table

I am querying a database and fetching the data directly into a class using PDO::FETCH_CLASS. Works great, one to one mapping of fields to class properties.

Now I need to join onto another table with a 1 to many relationship. For example, a person table and a car table, where a person can own multiple Cars.

The query isn't the problem, the data structure is.

I want my entity class to have a cars property, which can be filled with an array of the cars that person owns.

I can't find a way of doing this without running two queries, first selecting the person and populating the entity without any cars, then selecting their cars as an array and setting them on the entity using a setter.

But this is essentially 2 phase instantiation and feels wrong. There must be a better way to select the joined data into a property on my entity in a single query?

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