Propel2 icon indicating copy to clipboard operation
Propel2 copied to clipboard

Wrong property used for auto_increment value

Open Ka0o0 opened this issue 11 years ago • 1 comments

Hi,

When using an auto_increment field in an entity type (with idMethod native) with more than one primary key, the generated value (retrieved by lastInsertId) is saved into the wrong property.

In fact the auto_increment value is always saved in the first PK.

I created a short example. Here is my schema.xml

<?xml version="1.0" encoding="utf-8"?>
<database name="Test" defaultIdMethod="native" namespace="Test">

  <table name="table2" idMethod="native" phpName="Table1">
    <column name="pk1FK" phpName="IdentifyingFK" type="INTEGER" primaryKey="true" required="true"/>
    <column name="pk2" phpName="AutoID" type="INTEGER" autoIncrement="true" primaryKey="true" required="true"/>
    <column name="testcolumn" phpName="Test" type="VARCHAR" size="100" required="true"/>
    <foreign-key foreignTable="table1" phpName="Table1" onDelete="CASCADE" onUpdate="CASCADE">
      <reference local="pk1FK" foreign="pk1"/>
    </foreign-key>
    <vendor type="mysql">
      <parameter name="Engine" value="InnoDB"/>
    </vendor>
    <behavior name="timestampable" />
  </table>

  <table name="table1" idMethod="native" phpName="Table2">
    <column name="pk1" phpName="Pk" type="INTEGER" primaryKey="true" required="true"/>
    <vendor type="mysql">
      <parameter name="Engine" value="InnoDB"/>
    </vendor>
    <behavior name="timestampable" />
  </table>
</database>

The bug is in the generated Table1.php on line 844 where the identifyingPK is set but not the AutoID primary key.

screen shot 2014-10-04 at 17 34 52

should actually be

screen shot 2014-10-04 at 17 36 42

Ka0o0 avatar Oct 04 '14 15:10 Ka0o0

Is someone able to make a PR here with suggested changes?

dereuromark avatar Jul 01 '20 13:07 dereuromark