Extending / Storage Layer /
Working with Repositories

Repositories manage collections of entities. At a conceptual level where an
entity represents a row of data in the database, the repository represents the
table. When you request a repository in Bolt you will normally ask for it via
the name of the entity, and you will receive back an object that will be able
to perform find, save and delete operations on a collection of (or single)
entities.

Apart from more basic queries, which can use the simpler finder methods, the
primary method of querying the database is via a QueryBuilder instance. This
method fetches an instance of QueryBuilder that is preset to select on the
managed storage table.

The returned instance is always an object of type Doctrine\DBAL\Query\QueryBuilder.
Much more in-depth documentation for using this
can be found here.

Once you have finished building your query then you can fetch results by
calling ->execute() followed by one of ->fetch() or ->fetchAll().

For example the following fetches the ten most recent published entries and
for reference is functionally identical to the example in the findBy method
documentation below.

We can now graduate to more flexible querying on the storage layer. The findBy()
method allows us to pass key value parameters to the query which in turn filters
the results fetched from the storage layer.

As you can see from the accepted parameter list you can also pass in order,
limit and offset parameters to the method allowing you to perform most simple
queries using this method. For instance here is a query that finds the 10 most
recent published entries.

This method works identically to the findBy method above but will return a
single Entity object rather than a collection. This is most suited for when you
want to guarantee a single result, for example:

This method works identically to the findWith method above but will return a
single Entity object rather than a collection. This is most suited for when you
want to guarantee a single result, for example: