Skip to content

Commit

Permalink
Fixed reset sequence when auto increment columns is not first of prim…
Browse files Browse the repository at this point in the history
…ary key;
  • Loading branch information
edgardmessias committed Apr 28, 2016
1 parent 1bd682a commit b2f6b94
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,16 @@ public function resetSequence($table, $value = null)
} else {
// use master connection to get the biggest PK value
$value = $this->db->useMaster(function (Connection $db) use ($tableSchema) {
$key = reset($tableSchema->primaryKey);
$key = false;
foreach ($tableSchema->primaryKey as $name) {
if ($tableSchema->columns[$name]->autoIncrement) {
$key = $name;
break;
}
}
if($key === false){
return 0;
}
return $db->createCommand("SELECT MAX({$this->db->quoteColumnName($key)}) FROM {$this->db->quoteTableName($tableSchema->name)}")->queryScalar();
}) + 1;
}
Expand Down

0 comments on commit b2f6b94

Please sign in to comment.