ADR For ADR projects (see the flavor table in Overview).
An ADR project reads and writes its tables through repositories, not through the Active Record models of make:model. make:repository reads a table through the db service of the project, a Phalcon\DataMapper\Pdo\Connection (see The database), and writes a repository for it:
crest make:repository usersCreated src/Repository/Base/UsersRepositoryBase.php
Created src/Repository/UsersRepository.php
Nothing registers it: the container makes it when a class asks for it. Give
\App\Repository\UsersRepository to the constructor of an action or a domain class.
It needs the Phalcon\DataMapper\Pdo\Connection service, which the DbProvider
of crest new --database registers.| File | Owner | On another run |
|---|---|---|
src/Repository/Base/UsersRepositoryBase.php |
Crest | writes it again when the table changes |
src/Repository/UsersRepository.php |
you | keeps it, unless --force |
The base has the name of the table, its primary key and its columns (the constants TABLE, PRIMARY_KEY and COLUMNS). It also has four methods that use the primary key: find(), add(), update() and delete(). A row is an array, with the column names as keys. add() gives the id of the new row, and a null value writes NULL. Add the other queries of your application to UsersRepository, through $this->connection and $this->queryFactory.
The class name comes from the table name, as for make:model: user_profiles gives UserProfilesRepository. The table must have a primary key with one column. Crest stops on a table with no primary key, on a composite primary key, and on a table that the database does not have.