Describes the methods that any class representing a data storage should comply with.
Delete a single entity.
Deletes all records matching the provided conditions.
Returns true if there is any record in this repository matching the specified conditions.
Creates a new Query for this repository and applies some defaults based on the type of search that was selected.
Returns a single record after finding it by its primary key, if no record is found this method throws an exception.
Returns the repository alias.
Returns the table registry key used to create this table instance.
Test to see if a Repository has a specific field/column.
This creates a new entity object.
Create a list of entities + associated entities from an array.
Create a new entity + associated entities from an array.
Merges 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
.
Merges the passed $data
into $entity
respecting the accessible fields configured on the entity. Returns the same entity after being altered.
Creates a new Query instance for this repository
Persists 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.
Sets the repository alias.
Sets the table registry key used to create this table instance.
Update all matching records.
delete(Cake\Datasource\EntityInterface $entity, ArrayAccess|array $options = []): bool
Delete a single entity.
Deletes an entity and possibly related associations from the database based on the 'dependent' option used when defining the association.
Cake\Datasource\EntityInterface
$entity The entity to remove.
ArrayAccess|array
$options optional The options for the delete.
bool
deleteAll(mixed $conditions): int
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.
mixed
$conditions Conditions to be used, accepts anything Query::where() can take.
int
exists(array $conditions): bool
Returns true if there is any record in this repository matching the specified conditions.
array
$conditions list of conditions to pass to the query
bool
find(string $type = 'all', array<string, mixed> $options = []): Cake\Datasource\QueryInterface
Creates a new Query for this repository and applies some defaults based on the type of search that was selected.
string
$type optional the type of query to perform
array<string, mixed>
$options optional An array that will be passed to Query::applyOptions()
Cake\Datasource\QueryInterface
get(mixed $primaryKey, array<string, mixed> $options = []): Cake\Datasource\EntityInterface
Returns a single record after finding it by its primary key, if no record is found this method throws an exception.
$id = 10; $article = $articles->get($id); $article = $articles->get($id, ['contain' => ['Comments]]);
mixed
$primaryKey primary key value to find
array<string, mixed>
$options optional options accepted by Table::find()
Cake\Datasource\EntityInterface
Cake\Datasource\Exception\RecordNotFoundException
getAlias(): string
Returns the repository alias.
string
getRegistryAlias(): string
Returns the table registry key used to create this table instance.
string
hasField(string $field): bool
Test to see if a Repository has a specific field/column.
string
$field The field to check for.
bool
newEmptyEntity(): Cake\Datasource\EntityInterface
This creates a new entity object.
Careful: This does not trigger any field validation. This entity can be persisted without validation error as empty record. Always patch in required fields before saving.
Cake\Datasource\EntityInterface
newEntities(array $data, array<string, mixed> $options = []): arrayCake\Datasource\EntityInterface>
Create 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->getData());
The hydrated entities can then be iterated and saved.
array
$data The data to build an entity with.
array<string, mixed>
$options optional A list of options for the objects hydration.
arrayCake\Datasource\EntityInterface>
newEntity(array $data, array<string, mixed> $options = []): Cake\Datasource\EntityInterface
Create 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->getData());
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.
array
$data The data to build an entity with.
array<string, mixed>
$options optional A list of options for the object hydration.
Cake\Datasource\EntityInterface
patchEntities(iterableCake\Datasource\EntityInterface> $entities, array $data, array<string, mixed> $options = []): arrayCake\Datasource\EntityInterface>
Merges 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->getData());
iterableCake\Datasource\EntityInterface>
$entities the entities that will get the data merged in
array
$data list of arrays to be merged into the entities
array<string, mixed>
$options optional A list of options for the objects hydration.
arrayCake\Datasource\EntityInterface>
patchEntity(Cake\Datasource\EntityInterface $entity, array $data, array<string, mixed> $options = []): Cake\Datasource\EntityInterface
Merges 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->getData());
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<string, mixed>
$options optional A list of options for the object hydration.
Cake\Datasource\EntityInterface
query(): Cake\Datasource\QueryInterface
Creates a new Query instance for this repository
Cake\Datasource\QueryInterface
save(Cake\Datasource\EntityInterface $entity, ArrayAccess|array $options = []): Cake\Datasource\EntityInterface|false
Persists 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.
Cake\Datasource\EntityInterface
$entity the entity to be saved
ArrayAccess|array
$options optional The options to use when saving.
Cake\Datasource\EntityInterface|false
setAlias(string $alias): $this
Sets the repository alias.
string
$alias Table alias
$this
setRegistryAlias(string $registryAlias): $this
Sets the table registry key used to create this table instance.
string
$registryAlias The key used to access this object.
$this
updateAll(Cake\Database\Expression\QueryExpressionClosure|array|string $fields, mixed $conditions): int
Update 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.
Cake\Database\Expression\QueryExpressionClosure|array|string
$fields A hash of field => new value.
mixed
$conditions Conditions to be used, accepts anything Query::where() can take.
int
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/interface-Cake.Datasource.RepositoryInterface.html