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.
You can limit fields that will be present in the merged entity by
passing the fieldList option, which is also accepted for associations:
$article = $this->Articles->patchEntity($article, $this->request->data(), [
'fieldList' => ['title', 'body', 'tags', 'comments'],
'associated' => ['Tags', 'Comments.Users' => ['fieldList' => 'username']]
]
);
By default, the data is validated before being passed to the entity. In
the case of invalid fields, those will not be assigned to the entity.
The validate option can be used to disable validation on the passed data:
$article = $this->patchEntity($article, $this->request->data(),[
'validate' => false
]);
You can use the Model.beforeMarshal event to modify request data
before it is converted into entities.
public patchEntity ( Cake\Datasource\EntityInterface $entity, array $data, array $options = [] ) | ||
$entity | Cake\Datasource\EntityInterface | |
$data | array | |
$options | array |