-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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] Improve UUID and ULID support for Eloquent #44146
Conversation
if ($this->getKeyType() === 'string') { | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might need to be rethought. In my mind a string key type column can never be incrementing but I might be wrong.
$query = m::mock(Builder::class); | ||
$query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn('string id'); | ||
$query->shouldReceive('insert')->once()->with(['id' => 'string id']); | ||
$query->shouldReceive('getConnection')->once(); | ||
$model->expects($this->once())->method('newModelQuery')->willReturn($query); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to rewrite the test here because of the change I did in the getIncrementing
method. I think the current test wasn't realistic as I can't see how you can increment with string-based keys. With string-based keys you always need to set them beforehand afaik (like I adjusted the test to).
@driesvints why was the change to |
@taylorotwell whoops, you're right. Pushed. I first was thinking of doing it through a property but when you apply a trait with a property directly on a model you cannot overwrite it. The current solution is way better and more frictionless :) |
Good job! 👍 |
Maybe it's nice to add support for a binary column type for UUID? 😏 |
Hi @driesvints . This update break jenssegers/laravel-mongodb public function getIncrementing()
{
if ($this->getKeyType() === 'string') {
return false;
}
return $this->incrementing;
} |
@The-Hasanov I replied on the related PR fix: mongodb/laravel-mongodb#2452 |
Improves upon #44074 by:
incrementing
to false when astring
type primary key is usedI was doubting on checking to see if I could add support to use both traits at the same time (so you could both fill in UUID and ULID columns) but I guess that scenario isn't so common.