Interface RepositoryInterface
Describes the methods that any class representing a data storage should comply with.
Method Summary
- 
          alias() publicReturns the table alias or sets a new one 
- 
          delete() publicDelete a single entity. 
- 
          deleteAll() publicDelete all matching records. 
- 
          exists() publicReturns true if there is any record in this repository matching the specified conditions. 
- 
          find() publicCreates a new Query for this repository and applies some defaults based on the type of search that was selected. 
- 
          get() publicReturns a single record after finding it by its primary key, if no record is found this method throws an exception. 
- 
          hasField() publicTest to see if a Repository has a specific field/column. 
- 
          newEntities() publicCreate a list of entities + associated entities from an array. 
- 
          newEntity() publicCreate a new entity + associated entities from an array. 
- 
          patchEntities() publicMerges each of the elements passed in $datainto the entities found in$entitiesrespecting the accessible fields configured on the entities. Merging is done by matching the primary key in each of the elements in$dataand$entities.
- 
          patchEntity() publicMerges the passed $datainto$entityrespecting the accessible fields configured on the entity. Returns the same entity after being altered.
- 
          query() publicCreates a new Query instance for this repository 
- 
          save() publicPersists an entity based on the fields that are marked as dirty and returns the same entity after a successful save or false in case of any error. 
- 
          updateAll() publicUpdate all matching records. 
Method Detail
alias() ¶ public
alias(string|null $alias = null): stringReturns the table alias or sets a new one
Parameters
- 
                string|null$alias optional
- the new table alias 
Returns
stringdelete() ¶ public
delete(Cake\Datasource\EntityInterface $entity, array|ArrayAccess $options = []): boolDelete a single entity.
Deletes an entity and possibly related associations from the database based on the 'dependent' option used when defining the association.
Parameters
- 
                Cake\Datasource\EntityInterface$entity
- The entity to remove. 
- 
                array|ArrayAccess$options optional
- The options for the delete. 
Returns
boolsuccess
deleteAll() ¶ public
deleteAll(mixed $conditions): intDelete all matching records.
Deletes all records matching the provided conditions.
This method will not trigger beforeDelete/afterDelete events. If you need those first load a collection of records and delete them.
This method will not execute on associations' cascade attribute. You should
use database foreign keys + ON CASCADE rules if you need cascading deletes combined
with this method.
Parameters
- 
                mixed$conditions
- Conditions to be used, accepts anything Query::where() can take. 
Returns
intCount Returns the affected rows.
See Also
exists() ¶ public
exists(array|ArrayAccess $conditions): boolReturns true if there is any record in this repository matching the specified conditions.
Parameters
- 
                array|ArrayAccess$conditions
- list of conditions to pass to the query 
Returns
boolfind() ¶ public
find(string $type = 'all', array|ArrayAccess $options = []): Cake\ORM\QueryCreates a new Query for this repository and applies some defaults based on the type of search that was selected.
Model.beforeFind event
Each find() will trigger a Model.beforeFind event for all attached
listeners. Any listener can set a valid result set using $query
Parameters
- 
                string$type optional
- the type of query to perform 
- 
                array|ArrayAccess$options optional
- An array that will be passed to Query::applyOptions() 
Returns
Cake\ORM\Queryget() ¶ public
get(mixed $primaryKey, array|ArrayAccess $options = []): Cake\Datasource\EntityInterfaceReturns a single record after finding it by its primary key, if no record is found this method throws an exception.
Example:
$id = 10;
$article = $articles->get($id);
$article = $articles->get($id, ['contain' => ['Comments]]);Parameters
- 
                mixed$primaryKey
- primary key value to find 
- 
                array|ArrayAccess$options optional
- options accepted by - Table::find()
Returns
Cake\Datasource\EntityInterfaceThrows
Cake\Datasource\Exception\RecordNotFoundExceptionif the record with such id could not be found
See Also
hasField() ¶ public
hasField(string $field): boolTest to see if a Repository has a specific field/column.
Parameters
- 
                string$field
- The field to check for. 
Returns
boolTrue if the field exists, false if it does not.
newEntities() ¶ public
newEntities(array $data, array $options = []): arrayCreate a list of entities + associated entities from an array.
This is most useful when hydrating request data back into entities. For example, in your controller code:
$articles = $this->Articles->newEntities($this->request->data());The hydrated entities can then be iterated and saved.
Parameters
- 
                array$data
- The data to build an entity with. 
- 
                array$options optional
- A list of options for the objects hydration. 
Returns
arrayAn array of hydrated records.
newEntity() ¶ public
newEntity(array|null $data = null, array $options = []): Cake\Datasource\EntityInterfaceCreate a new entity + associated entities from an array.
This is most useful when hydrating request data back into entities. For example, in your controller code:
$article = $this->Articles->newEntity($this->request->data());The hydrated entity will correctly do an insert/update based on the primary key data existing in the database when the entity is saved. Until the entity is saved, it will be a detached record.
Parameters
- 
                array|null$data optional
- The data to build an entity with. 
- 
                array$options optional
- A list of options for the object hydration. 
Returns
Cake\Datasource\EntityInterfacepatchEntities() ¶ public
patchEntities(array|Traversable $entities, array $data, array $options = []): arrayMerges each of the elements passed in $data into the entities
found in $entities respecting the accessible fields configured on the entities.
Merging is done by matching the primary key in each of the elements in $data
and $entities.
This is most useful when editing a list of existing entities using request data:
$article = $this->Articles->patchEntities($articles, $this->request->data());Parameters
- 
                array|Traversable$entities
- the entities that will get the data merged in 
- 
                array$data
- list of arrays to be merged into the entities 
- 
                array$options optional
- A list of options for the objects hydration. 
Returns
arraypatchEntity() ¶ public
patchEntity(Cake\Datasource\EntityInterface $entity, array $data, array $options = []): Cake\Datasource\EntityInterfaceMerges the passed $data into $entity respecting the accessible
fields configured on the entity. Returns the same entity after being
altered.
This is most useful when editing an existing entity using request data:
$article = $this->Articles->patchEntity($article, $this->request->data());Parameters
- 
                Cake\Datasource\EntityInterface$entity
- the entity that will get the data merged in 
- 
                array$data
- key value list of fields to be merged into the entity 
- 
                array$options optional
- A list of options for the object hydration. 
Returns
Cake\Datasource\EntityInterfacequery() ¶ public
query(): Cake\ORM\QueryCreates a new Query instance for this repository
Returns
Cake\ORM\Querysave() ¶ public
save(Cake\Datasource\EntityInterface $entity, array|ArrayAccess $options = []): Cake\Datasource\EntityInterface|boolPersists an entity based on the fields that are marked as dirty and returns the same entity after a successful save or false in case of any error.
Parameters
- 
                Cake\Datasource\EntityInterface$entity
- the entity to be saved 
- 
                array|ArrayAccess$options optional
- The options to use when saving. 
Returns
Cake\Datasource\EntityInterface|boolupdateAll() ¶ public
updateAll(array $fields, mixed $conditions): intUpdate all matching records.
Sets the $fields to the provided values based on $conditions. This method will not trigger beforeSave/afterSave events. If you need those first load a collection of records and update them.
Parameters
- 
                array$fields
- A hash of field => new value. 
- 
                mixed$conditions
- Conditions to be used, accepts anything Query::where() can take. 
Returns
intCount Returns the affected rows.
