Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!