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?