From a00d2ae0b90824fd7b438bbcc4f4baf70a7b6f1b Mon Sep 17 00:00:00 2001 From: WebsourceCz Date: Wed, 25 Nov 2020 16:56:10 +0100 Subject: [PATCH] When inserting rows into crossRef table with auto increment primary key column defined at other than first position in table schema, then auto increment value is set to first defined primary key column instead of the correct one. --- src/Propel/Generator/Builder/Om/ObjectBuilder.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Propel/Generator/Builder/Om/ObjectBuilder.php b/src/Propel/Generator/Builder/Om/ObjectBuilder.php index 65ef45f0c7..55c3aff211 100644 --- a/src/Propel/Generator/Builder/Om/ObjectBuilder.php +++ b/src/Propel/Generator/Builder/Om/ObjectBuilder.php @@ -6609,16 +6609,18 @@ protected function addDoInsertBodyRaw() } catch (Exception \$e) { throw new PropelException('Unable to get autoincrement id.', 0, \$e); }"; - $column = $table->getFirstPrimaryKeyColumn(); - if ($column) { + foreach ($table->getPrimaryKey() as $col) { + if (!$col->isAutoIncrement()) { + continue; + } if ($table->isAllowPkInsert()) { $script .= " if (\$pk !== null) { - \$this->set" . $column->getPhpName() . "(\$pk); + \$this->set" . $col->getPhpName() . "(\$pk); }"; } else { $script .= " - \$this->set" . $column->getPhpName() . '($pk);'; + \$this->set" . $col->getPhpName() . '($pk);'; } } $script .= "