Skip to content

Commit aa5a5f2

Browse files
committed
Structure::getPrimaryKeySequence(): fixed retrieving sequence name if table has composite PK
1 parent bf899b4 commit aa5a5f2

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Database/Structure.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ public function getPrimaryKeySequence($table)
7474
}
7575

7676
$primary = $this->getPrimaryKey($table);
77-
if (!$primary || is_array($primary)) {
77+
if (!$primary) {
7878
return NULL;
7979
}
8080

81-
foreach ($this->structure['columns'][$table] as $columnMeta) {
82-
if ($columnMeta['name'] === $primary) {
83-
return isset($columnMeta['vendor']['sequence']) ? $columnMeta['vendor']['sequence'] : NULL;
81+
foreach ((array) $primary as $key) {
82+
foreach ($this->structure['columns'][$table] as $columnMeta) {
83+
if ($columnMeta['name'] === $key) {
84+
return isset($columnMeta['vendor']['sequence']) ? $columnMeta['vendor']['sequence'] : NULL;
85+
}
8486
}
8587
}
8688

tests/Database/Table/bugs/Selection.insert().phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ test(function () use ($context) {
3838
//Insert into table with composite primary key and one of them is auto_increment
3939
test(function () use ($context, $driverName) {
4040

41-
//Sqlite doesn't allow this type of table and sqlsrv's driver don't implement reflection, i don't know now why this not working in pgsql
42-
if ($driverName == 'mysql') {
41+
//Sqlite doesn't allow this type of table and sqlsrv's driver don't implement reflection
42+
if ($driverName == 'mysql' || $driverName == 'pgsql') {
4343
$inserted = $context->table('composite_pk_ai')->insert([
4444
'id2' => 10,
4545
'name' => 'Michal'

0 commit comments

Comments
 (0)