Skip to content

Commit

Permalink
Fixed: removal of embedded objects not allowed by recursive array merge
Browse files Browse the repository at this point in the history
in update()
  • Loading branch information
leogr committed Jul 21, 2015
1 parent d0bfbbb commit 75f1076
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Model/MatryoshkaConnectedResource.php
Expand Up @@ -242,17 +242,21 @@ public function update($id, $data)
return $oldObject;
}

// Merge new data on top old one
$data = ArrayUtils::merge(
// $data could not cointain all fields so we merge new data on top the old one
$data = array_merge(
$this->retrieveHydrator($oldObject)->extract($oldObject),
$this->retrieveData($data)
);

// Get a new object instance in order to ensure that a new entity class can work properly
// Get a new object instance in order to ensure that saving operation
// can work properly even if the entity class is different
if ($entityClass = $this->getEntityClass()) {
$object = $this->getObjectManager()->get($entityClass);
} else {
$object = $this->getPrototypeStrategy()->createObject($this->model->getObjectPrototype(), $data);
$object = $this->getPrototypeStrategy()->createObject(
$this->getModel()->getObjectPrototype(),
$data
);
}

// Finally, hydrate and save the new object, replacing the old one
Expand All @@ -271,7 +275,7 @@ public function update($id, $data)
*/
public function patch($id, $data)
{
// TODO: a partial update should be applied
// TODO: a partial update could be applied if a specific criteria is available
return $this->update($id, $data);
}

Expand Down

0 comments on commit 75f1076

Please sign in to comment.