Skip to content
Permalink
Browse files

Don't overwrite an entity's id when it was specified.

When an entity is persisted with a specific ID, we should not overwrite
that value with the generated, but unused value.

Refs #7225
  • Loading branch information...
markstory committed Aug 30, 2015
1 parent bbe5357 commit 0033fefef797a85e5cbb1e1b7f6f26dd11003a4e
Showing with 5 additions and 0 deletions.
  1. +4 −0 src/ORM/Table.php
  2. +1 −0 tests/TestCase/ORM/TableUuidTest.php
@@ -1487,7 +1487,11 @@ protected function _insert($entity, $data)
}
$keys = array_fill(0, count($primary), null);
$id = (array)$this->_newId($primary) + $keys;
// Generate primary keys preferring values in $data.
$primary = array_combine($primary, $id);
$primary = array_intersect_key($data, $primary) + $primary;
$filteredKeys = array_filter($primary, 'strlen');
$data = $data + $filteredKeys;
@@ -97,6 +97,7 @@ public function testSaveNewSpecificId()
]);
$table = TableRegistry::get('uuiditems');
$this->assertSame($entity, $table->save($entity));
$this->assertSame($id, $entity->id);
$row = $table->find('all')->where(['id' => $id])->first();
$this->assertNotEmpty($row);

0 comments on commit 0033fef

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.