I have a domain model and a data mapper built with PHP and MySql. Some domain objects appear only in the context of others and in these cases I am using dependent mappings, i.e. the dependent objects do not have their own mapper, but are instead persisted by their owner's mapper.
For performance reasons I am joining multiple tables and issuing one SQL query, (rather than one query per table), and this is where the difficulty arises: the results of my queries are cartesian joins (of course) and will require a fair amount of array sifting to get sensible data with which to populate domain objects.
For example, I have three tables: one parent (P1) and two children (C1 and C2). If a single record in P1 has two records in both C1 and C2, I have four records in my result set. I can cycle through the result set array looking for unique values and create a fresh array from these, but that seems like a lot of work.
This is bound to be a common problem. What is the typical way to solve it? I looked through the SPL data structures and iterators but didn't find anything useful. I don't want to split into multiple queries unless I really have to.
Thanks!