Skip to content

Commit

Permalink
Adding the SaveOptionsBuilder to the table object.
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Jul 20, 2016
1 parent c752833 commit 051f236
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/ORM/Table.php
Expand Up @@ -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,
Expand Down Expand Up @@ -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()]);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 051f236

Please sign in to comment.