Skip to content

Commit

Permalink
Fix incrementing string keys (#44247)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Sep 22, 2022
1 parent 75cae48 commit b5b0288
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/Illuminate/Database/Eloquent/Concerns/HasUlids.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ public function getKeyType()

return $this->keyType;
}

/**
* Get the value indicating whether the IDs are incrementing.
*
* @return bool
*/
public function getIncrementing()
{
if (in_array($this->getKeyName(), $this->uniqueIds())) {
return false;
}

return $this->incrementing;
}
}
14 changes: 14 additions & 0 deletions src/Illuminate/Database/Eloquent/Concerns/HasUuids.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ public function getKeyType()

return $this->keyType;
}

/**
* Get the value indicating whether the IDs are incrementing.
*
* @return bool
*/
public function getIncrementing()
{
if (in_array($this->getKeyName(), $this->uniqueIds())) {
return false;
}

return $this->incrementing;
}
}
4 changes: 0 additions & 4 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1851,10 +1851,6 @@ public function setKeyType($type)
*/
public function getIncrementing()
{
if ($this->getKeyType() === 'string') {
return false;
}

return $this->incrementing;
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2216,10 +2216,9 @@ public function testIntKeyTypePreserved()
public function testStringKeyTypePreserved()
{
$model = $this->getMockBuilder(EloquentKeyTypeModelStub::class)->onlyMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock();
$model->id = 'string id';

$query = m::mock(Builder::class);
$query->shouldReceive('insert')->once()->with(['id' => 'string id']);
$query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn('string id');
$query->shouldReceive('getConnection')->once();
$model->expects($this->once())->method('newModelQuery')->willReturn($query);

Expand Down

0 comments on commit b5b0288

Please sign in to comment.