[TYPO3-dev] Fetch several 1:N relations in one query and map to objects

Olle Haerstedt o.haerstedt at bitmotion.de
Mon Sep 8 17:01:29 CEST 2014


Hi!

I have a query with several nested 1:N relations. Is it possible to do _one_ query and then map the rows to objects, instead of getting hit by the ORM N+1 problem?

Example, where one client has many projects, which in turn have many packets.

SELECT
  *
FROM
  client
JOIN
  project ON project.client_id = client.id
JOIN
  packet ON packet.project_id = project.id
..

PHP pseudo-code would be something like

$clients = parse_clients($result);
foreach ($clients as $client) {
  $client->projects = parse_projects($result, $client);
  foreach ($client->projects as $project) {
    $project->packets = parse_packets($result, $project);
  }
}

Regards
Olle



More information about the TYPO3-dev mailing list