Skip to content

Commit

Permalink
Use insert instead of insertGetId when using custom primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiCollin committed May 16, 2015
1 parent 4d1a7f6 commit e1ad662
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/Commands/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,19 @@ protected function insert()

$attributes = $this->getRawAttributes();

$id = $this->query->insertGetId($attributes);

$keyName = $this->entityMap->getKeyName();

$entity->setEntityAttribute($keyName, $id);

// Check if the primary key is defined in the attributes
if(array_key_exists($keyName, $attributes))
{
$this->query->insert($attributes);
}
else
{
$id = $this->query->insertGetId($attributes);

$entity->setEntityAttribute($keyName, $id);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/AnalogueTest/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ public function testSelfGeneratedPrimaryKey()
$uuid = new Uuid('test', 'testlabel');
$um = get_mapper($uuid);
$um->store($uuid);

$this->assertEquals('test', $uuid->uuid);
$uuid = $um->where('uuid', '=', 'test')->first();

$this->assertEquals('test', $uuid->uuid);
$this->assertEquals('testlabel', $uuid->label);

}
Expand Down
Binary file modified tests/test.sqlite
Binary file not shown.

0 comments on commit e1ad662

Please sign in to comment.