Describes the methods that any class representing a data storage should comply with.
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.
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.
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.
alias( string|null $alias null )
Returns the table alias or sets a new one
$alias
optional null delete( Cake\Datasource\EntityInterface $entity , array|ArrayAccess $options [] )
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
$options
optional [] deleteAll( mixed $conditions )
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.
$conditions
Conditions to be used, accepts anything Query::where() can take.
exists( array|ArrayAccess $conditions )
Returns true if there is any record in this repository matching the specified conditions.
$conditions
find( string $type 'all' , array|ArrayAccess $options [] )
Creates a new Query for this repository and applies some defaults based on the type of search that was selected.
Each find() will trigger a Model.beforeFind
event for all attached listeners. Any listener can set a valid result set using $query
$type
optional 'all' $options
optional [] Cake\ORM\Query
get( mixed $primaryKey , array|ArrayAccess $options [] )
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]]);
$primaryKey
$options
optional [] Table::find()
Cake\Datasource\EntityInterface
Cake\Datasource\Exception\RecordNotFoundException
if the record with such id could not be found
hasField( string $field )
Test to see if a Repository has a specific field/column.
$field
newEntities( array $data , array $options [] )
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.
$data
$options
optional [] newEntity( array|null $data null , array $options [] )
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.
$data
optional null $options
optional [] Cake\Datasource\EntityInterface
patchEntities( array|Traversable $entities , array $data , array $options [] )
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());
$entities
the entities that will get the data merged in
$data
$options
optional [] patchEntity( Cake\Datasource\EntityInterface $entity , array $data , array $options [] )
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
$data
$options
optional [] Cake\Datasource\EntityInterface
query( )
Creates a new Query instance for this repository
Cake\ORM\Query
save( Cake\Datasource\EntityInterface $entity , array|ArrayAccess $options [] )
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
$options
optional [] Cake\Datasource\EntityInterface
|booleanupdateAll( string|array|callable|Cake\Database\Expression\QueryExpression $fields , mixed $conditions )
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\QueryExpression
$fields
$conditions
Conditions to be used, accepts anything Query::where() can take.
© 2005–2017 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/3.4/class-Cake.Datasource.RepositoryInterface.html