Oihana PHP

UpdateModel

Contract for models able to update an existing document.

An UpdateModel exposes a single UpdateModel::update() operation that applies a partial change to an existing document, merging the supplied fields into the stored one. For a full document overwrite, see ReplaceModel.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Methods

update()  : mixed
Updates an existing document in the model.

Methods

update()

Updates an existing document in the model.

public update([array<string|int, mixed> $init = [] ]) : mixed
Parameters
$init : array<string|int, mixed> = []

Operation options carrying the change to apply, typically the target key/id, the document patch to merge, optional binds and a return clause.

Tags
example
use oihana\models\interfaces\UpdateModel;

class UserModel implements UpdateModel
{
    public function update( array $init = [] ) : mixed
    {
        return $this->store->patch( $init[ 'key' ], $init[ 'document' ] ?? [] ) ;
    }
}

$model = new UserModel() ;
$user  = $model->update( [ 'key' => 'users/42', 'document' => [ 'active' => false ] ] ) ;
Return values
mixed

The updated document (or its result), depending on the implementation.

On this page

Search results