Build crashes when no primaryKey on autoIncrement column #564

Closed
jonphipps opened this Issue Mar 4, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@jonphipps

In reverse engineering a MySql database, I discovered that there are apparently several tables in which there is an integer ID column that is autoIncrement but is not a primaryKey:

    <column name="id" phpName="Id" type="INTEGER" autoIncrement="true" required="true"/>

This causes quite a nice crash during a build in src/Propel/Generator/Builder/Om/ObjectBuilder.php->addDoInsertBodyRaw() on line 4839:

\$this->set".$column->getPhpName()."(\$pk);";

...since the table has an autoincrementing key, but the 'primaryKey' $column is null. It would seem that there should be a check somewhere before it crashes, either as a post-generation check on the reverse engineering, or a build preflight of the schema.xml file, or an exception thrown at the point of failure.

Simply ensuring that an autoIncrement column is also a primryKey column is the quick fix, once I figured out what was going on:

    <column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>

@marcj marcj added the Bug label Mar 4, 2014

@marcj

This comment has been minimized.

Show comment
Hide comment
@marcj

marcj Mar 4, 2014

Member

Good catch. Feel free to submit a PR if you get to it before we do.

Member

marcj commented Mar 4, 2014

Good catch. Feel free to submit a PR if you get to it before we do.

@marcj marcj added this to the alpha-3 milestone Mar 13, 2014

@marcj marcj closed this in bfa4ac3 Apr 11, 2014

mpscholten added a commit to mpscholten/Propel2 that referenced this issue Aug 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment