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

135
Vistas
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 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