Skip to content
Permalink
Browse files

Extract primary key value generation into a separate method.

This allows users the ability to override pk generation if they don't
want to use the type system.
  • Loading branch information...
markstory committed Nov 11, 2013
1 parent 339ff2d commit 9db0f8871f93bc2ee22f11cba7e7fde7659d8c38
Showing with 20 additions and 6 deletions.
  1. +20 −6 Cake/ORM/Table.php
@@ -867,13 +867,8 @@ protected function _processSave($entity, $options) {
protected function _insert($entity, $data) {
$query = $this->_buildQuery();
$id = null;
$primary = $this->primaryKey();
if ($primary) {
$typeName = $this->schema()->columnType($primary);
$type = Type::build($typeName);
$id = $type->newId();
}
$id = $this->_newId($primary);
if ($id !== null) {
$data[$primary] = $id;
}
@@ -897,6 +892,25 @@ protected function _insert($entity, $data) {
return $success;
}
/**
* Generate a primary key value for a new record.
*
* By default, this uses the type system to generate a new primary key
* value if possible. You can override this method if you have specific requirements
* for id generation.
*
* @param string $primary The primary key column to get a new ID for.
* @return null|mixed Either null or the new primary key value.
*/
protected function _newId($primary) {
if (!$primary) {
return null;
}
$typeName = $this->schema()->columnType($primary);
$type = Type::build($typeName);
return $type->newId();
}
/**
* Auxiliary function to handle the update of an entity's data in the table
*

0 comments on commit 9db0f88

Please sign in to comment.
You can’t perform that action at this time.