Skip to content

Commit

Permalink
Don't set primary key for non-auto-inc columns
Browse files Browse the repository at this point in the history
  • Loading branch information
nox7 committed May 10, 2022
1 parent c184299 commit d931406
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ORM/ModelClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public function __construct(ModelInstance $modelClass){
public function save(): void{
$abyss = new Abyss();
$rowID = $abyss->saveOrCreate($this);
if ($rowID !== null){

// 0 Here would indicate a column that doesn't generate an automatically incremented ID
if ($rowID !== null && $rowID !== 0){
$primaryKeyClassPropertyName = $abyss->getPrimaryKey($this::getModel());
if ($primaryKeyClassPropertyName) {
$this->$primaryKeyClassPropertyName = $rowID;
Expand Down

0 comments on commit d931406

Please sign in to comment.