Fabian Fritz Fabian Fritz - 6 months ago 3x
PHP Question

Combining two QueryResults in a Extbase Repository

I'm programming a TYPO3 - extension for a website. Since I'm using the Extbase Framework I have a Repository class (Tx_Extbase_Persistence_Repository) where I do two sql queries in a row:

$query1 = $this->createQuery();
$res1 = $query1->execute();

$query2 = $this->createQuery();
$res1 = $query2->execute();

1 and
contain a
. Now I want to return the combined result and I have no idea how this is done. Returning the raw array isn't an option because I'm relying on the functions of the
class, and also I want to avoid to combine the sql(UNION, JOIN). I already tried this:

$myResult = $this->objectManager->create('Tx_Extbase_Persistence_ObjectStorage')
foreach($res1 as $obj) {
//foreach $res2

..but this throws an error (
"could not determine the child object type"

So how do you properly combine two


With combining I mean instead of two separate
I want just one which contains both the results from
as well as
. An SQL-UNION or JOIN unfortunately isn't an option.


QueryResult implements QueryResultInterface which extends among others ArrayAccess. With this you can use the offsetSet method.

foreach ($res2->toArray() as $result) {
  $res1->offsetSet(($res1->count()), $result);

The QueryResult $res1 contain now the objects from $res2 too.