$_table
$_table : \Cake\ORM\Table
The table instance this marshaller is for.
Contains logic to convert array data into entities.
Useful when converting request data into entities.
$_table : \Cake\ORM\Table
The table instance this marshaller is for.
__construct(\Cake\ORM\Table $table)
Constructor.
\Cake\ORM\Table | $table | The table this marshaller is for. |
one(array $data, array $options = array()) : \Cake\Datasource\EntityInterface
Hydrate one entity and its associated data.
The above options can be used in each nested associated
array. In addition to the above
options you can also use the onlyIds
option for HasMany and BelongsToMany associations.
When true this option restricts the request data to only be read from _ids
.
$result = $marshaller->one($data, [
'associated' => ['Tags' => ['onlyIds' => true]]
]);
array | $data | The data to hydrate. |
array | $options | List of options |
many(array $data, array $options = array()) : array<mixed,\Cake\Datasource\EntityInterface>
Hydrate many entities and their associated data.
array | $data | The data to hydrate. |
array | $options | List of options |
An array of hydrated records.
merge(\Cake\Datasource\EntityInterface $entity, array $data, array $options = array()) : \Cake\Datasource\EntityInterface
Merges `$data` into `$entity` and recursively does the same for each one of the association names passed in `$options`. When merging associations, if an entity is not present in the parent entity for a given association, a new one will be created.
When merging HasMany or BelongsToMany associations, all the entities in the
$data
array will appear, those that can be matched by primary key will get
the data merged, but those that cannot, will be discarded. ids
option can be used
to determine whether the association must use the _ids
format.
The above options can be used in each nested associated
array. In addition to the above
options you can also use the onlyIds
option for HasMany and BelongsToMany associations.
When true this option restricts the request data to only be read from _ids
.
$result = $marshaller->merge($entity, $data, [
'associated' => ['Tags' => ['onlyIds' => true]]
]);
\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 | List of options. |
mergeMany(array<mixed,\Cake\Datasource\EntityInterface>|\Traversable $entities, array $data, array $options = array()) : array<mixed,\Cake\Datasource\EntityInterface>
Merges each of the elements from `$data` into each of the entities in `$entities` and recursively does the same for each of the association names passed in `$options`. When merging associations, if an entity is not present in the parent entity for a given association, a new one will be created.
Records in $data
are matched against the entities using the primary key
column. Entries in $entities
that cannot be matched to any record in
$data
will be discarded. Records in $data
that could not be matched will
be marshalled as a new entity.
When merging HasMany or BelongsToMany associations, all the entities in the
$data
array will appear, those that can be matched by primary key will get
the data merged, but those that cannot, will be discarded.
array<mixed,\Cake\Datasource\EntityInterface>|\Traversable | $entities | the entities that will get the data merged in |
array | $data | list of arrays to be merged into the entities |
array | $options | List of options. |
_normalizeAssociations(array $associations) : array
Returns an array out of the original passed associations list where dot notation is transformed into nested arrays so that they can be parsed by other routines
array | $associations | The array of included associations. |
An array having dot notation transformed into nested arrays
_buildPropertyMap(array $data, array $options) : array
Build the map of property => marshalling callable.
array | $data | The data being marshalled. |
array | $options | List of options containing the 'associated' key. |
When associations do not exist.
_validate(array $data, array $options, boolean $isNew) : array
Returns the validation errors for a data set based on the passed options
array | $data | The data to validate. |
array | $options | The options passed to this marshaller. |
boolean | $isNew | Whether it is a new entity or one to be updated. |
If no validator can be created.
The list of validation errors.
_prepareDataAndOptions(array $data, array $options) : array
Returns data and options prepared to validate and marshall.
array | $data | The data to prepare. |
array | $options | The options passed to this marshaller. |
An array containing prepared data and options.
_marshalAssociation(\Cake\ORM\Association $assoc, array $value, array $options) : \Cake\Datasource\EntityInterface|array<mixed,\Cake\Datasource\EntityInterface>|null
Create a new sub-marshaller and marshal the associated data.
\Cake\ORM\Association | $assoc | The association to marshall |
array | $value | The data to hydrate |
array | $options | List of options. |
_belongsToMany(\Cake\ORM\Association\BelongsToMany $assoc, array $data, array $options = array()) : array<mixed,\Cake\Datasource\EntityInterface>
Marshals data for belongsToMany associations.
Builds the related entities and handles the special casing for junction table entities.
\Cake\ORM\Association\BelongsToMany | $assoc | The association to marshal. |
array | $data | The data to convert into entities. |
array | $options | List of options. |
An array of built entities.
_loadAssociatedByIds(\Cake\ORM\Association $assoc, array $ids) : array<mixed,\Cake\Datasource\EntityInterface>
Loads a list of belongs to many from ids.
\Cake\ORM\Association | $assoc | The association class for the belongsToMany association. |
array | $ids | The list of ids to load. |
An array of entities.
_loadBelongsToMany(\Cake\ORM\Association $assoc, array $ids) : array<mixed,\Cake\Datasource\EntityInterface>
Loads a list of belongs to many from ids.
\Cake\ORM\Association | $assoc | The association class for the belongsToMany association. |
array | $ids | The list of ids to load. |
An array of entities.
_mergeAssociation(\Cake\Datasource\EntityInterface|array<mixed,\Cake\Datasource\EntityInterface> $original, \Cake\ORM\Association $assoc, array $value, array $options) : \Cake\Datasource\EntityInterface|array<mixed,\Cake\Datasource\EntityInterface>|null
Creates a new sub-marshaller and merges the associated data.
\Cake\Datasource\EntityInterface|array<mixed,\Cake\Datasource\EntityInterface> | $original | The original entity |
\Cake\ORM\Association | $assoc | The association to merge |
array | $value | The data to hydrate |
array | $options | List of options. |
None found |
_mergeBelongsToMany(\Cake\Datasource\EntityInterface $original, \Cake\ORM\Association $assoc, array $value, array $options) : array<mixed,\Cake\Datasource\EntityInterface>
Creates a new sub-marshaller and merges the associated data for a BelongstoMany association.
\Cake\Datasource\EntityInterface | $original | The original entity |
\Cake\ORM\Association | $assoc | The association to marshall |
array | $value | The data to hydrate |
array | $options | List of options. |
None found |
_mergeJoinData(\Cake\Datasource\EntityInterface $original, \Cake\ORM\Association\BelongsToMany $assoc, array $value, array $options) : array<mixed,\Cake\Datasource\EntityInterface>
Merge the special _joinData property into the entity set.
\Cake\Datasource\EntityInterface | $original | The original entity |
\Cake\ORM\Association\BelongsToMany | $assoc | The association to marshall |
array | $value | The data to hydrate |
array | $options | List of options. |
An array of entities
None found |