Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fix incrementing string keys #44247

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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