diff --git a/src/ORM/Table.php b/src/ORM/Table.php index f47ad053fcd..315fe9a6809 100644 --- a/src/ORM/Table.php +++ b/src/ORM/Table.php @@ -1442,6 +1442,10 @@ public function exists($conditions) */ public function save(EntityInterface $entity, $options = []) { + if ($options instanceof SaveOptionsBuilder) { + $options = $options->toArray(); + } + $options = new ArrayObject($options + [ 'atomic' => true, 'associated' => true, @@ -2113,6 +2117,10 @@ public function marshaller() */ public function newEntity($data = null, array $options = []) { + if ($options instanceof SaveOptionsBuilder) { + $options = $options->toArray(); + } + if ($data === null) { $class = $this->entityClass(); $entity = new $class([], ['source' => $this->registryAlias()]); @@ -2157,6 +2165,10 @@ public function newEntity($data = null, array $options = []) */ public function newEntities(array $data, array $options = []) { + if ($options instanceof SaveOptionsBuilder) { + $options = $options->toArray(); + } + if (!isset($options['associated'])) { $options['associated'] = $this->_associations->keys(); } @@ -2198,6 +2210,10 @@ public function newEntities(array $data, array $options = []) */ public function patchEntity(EntityInterface $entity, array $data, array $options = []) { + if ($options instanceof SaveOptionsBuilder) { + $options = $options->toArray(); + } + if (!isset($options['associated'])) { $options['associated'] = $this->_associations->keys(); } @@ -2233,6 +2249,10 @@ public function patchEntity(EntityInterface $entity, array $data, array $options */ public function patchEntities($entities, array $data, array $options = []) { + if ($options instanceof SaveOptionsBuilder) { + $options = $options->toArray(); + } + if (!isset($options['associated'])) { $options['associated'] = $this->_associations->keys(); } @@ -2364,6 +2384,16 @@ public function buildRules(RulesChecker $rules) return $rules; } + /** + * Gets a SaveOptionsBuilder instance. + * + * @return \Cake\ORM\SaveOptionsBuilder + */ + public function getSaveOptionsBuilder() + { + return new SaveOptionsBuilder(); + } + /** * Loads the specified associations in the passed entity or list of entities * by executing extra queries in the database and merging the results in the