Using a query container

Edit on GitHub
When to use query containers

Don’t use query containers to cross module boundaries, as this increases modules coupling. However, you can use them behind Repository and Entity Manager as query aggregations. Previously, query containers were used to cross module borders (via dependency providers), which led to higher module coupling and leaking of persistence layer from one domain object to another, and therefore, to higher maintenance efforts and lower code reusability. This approach has been deprecated now, 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 the business layer and can be injected into any model.

Query container via factory

Executing the query

You can adjust the query itself, but you should avoid adding more filters or joins because this is a 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);