When saving to a model that doesn't follow the cake convention and has
no auto_increment primary key, save makes a call to lastInsertID,
which in turn calls $data = $this->fetchAll('SELECT LAST_INSERT_ID()
as id From '.$source). The fetchAll returns all the records in a table
and for a large table this makes $this->save() unacceptably slow.
LAST_INSERT_ID is suppose to return the "LAST" inserted id and *not*
all of the insertsed IDs in a multi-insert operation. Within the
"function lastInsertId", the fetchAll should be changed to fetchArray
instead.
Can somebody confirm that my change below is correct:
function lastInsertId($source = null) {
$id = mysql_insert_id($this->connection);
if ($id) {
return $id;
}
// $data = $this->fetchAll('SELECT LAST_INSERT_ID() as
id From '.$source);
// if ($data && isset($data[0]['id'])) {
// return $data[0]['id'];
$data = $this->fetchArray('SELECT LAST_INSERT_ID() as
id From '.$source);
if ($data && isset($data['id'])) {
return $data['id'];
}
}
--
[EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---