Using a query container

Edit on GitHub
When to use query containers

Don’t use query containers to cross-module boundaries, as this increases module coupling. However, you can use them behind Repository and Entity Manager as query aggregations. Previously, query containers were used to cross-module borders (using dependency providers), which led to higher module coupling and leaking of the Persistence layer from one domain object to another, and therefore, to higher maintenance efforts and lower code reusability. This approach is deprecated, so we don’t recommend using query containers like this in your project development.

The query container of the current unterminated query is available via $this->getQueryContainer() in the factory of the Communication and Business layers and can be injected into any model.

Query container via factory

Executing the query

You can adjust the query itself, but avoid adding more filters or joins because this is the responsibility of the query container only.

<?php
$templateQuery = $this->queryTemplateByPath($path);
$templateQuery->limit(100);
$templateQuery->offset(10);
$templateCollection = $templateQuery->find(); // or findOne()

You can also change the output format—for example, to array instead of collection:

<?php
$formatter = new SimpleArrayFormatter();
$templateQuery->setFormatter($formatter);