About the Query Container

Edit on GitHub

A query container holds all the database queries of the current module.

Each module has exactly one query container, which also acts as an entry point to the persistence layer. Internally, it uses query objects and returns unterminated queries.

As you can see in the example below, the query container consists of query-methods which gets query objects from the factory, adds some filters or joins and returns the unterminated query object.

Unterminated queries should be avoided in the Application Layers above Persistence. Consider using the Repository and Entity Manager patterns to decouple persistence and ORM implementation details.

Unterminated means you don’t execute the query with find(), findOne() or count().

use Spryker\Zed\Kernel\Persistence\AbstractQueryContainer;

/**
 * @method \Pyz\Zed\MyBundle\Persistence\MyBundlePersistenceFactory getFactory()
 */
class MyBundleQueryContainer extends AbstractQueryContainer implements MyBundleQueryContainerInterface
{
    public function queryTemplateByPath($path)
    {
        $query = $this->getFactory()->createTemplateQuery();
        $query->filterByTemplatePath($path);

        return $query;
    }
}

You might use the following definitions to generate the related code:

  • vendor/bin/console spryk:run AddZedPersistencePropelAbstractQuery - Add Zed Persistence Propel Abstract Query

See the Spryk documentation for details.

What’s next?