-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Overriding $primaryKey is still an issue #1958
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Hello, That's definitely a bug, however not sure why it was reverted back to fix a "tests"? No explanation was given from @jenssegers so we're on just our own. @Smolevich @Giacomo92 @rennokki any suggestions what we need to do? Thank you! |
You should create a command to do that |
@paouriel I experienced this same issue today and I tracked it down to having tried to create a record with a null value for my custom primary key. When passing a valid value it to works fine. Perhaps an error message for when the custom primary key is null would be helpful. |
Is there any update? |
@Smolevich I have looked into this issue and found that this issue exists. The Builder uses a hard-coded string _id for its primary key. Should I make a pull request to fix this? |
@stephandesouza it's an easy fix but some tests are failing. This is the main reason why it's being delayed. However, I might take a look soon. |
I've just checked this and can confirm that there is no issue at all. $check = Book::find('A Game of Thrones');
$this->assertEquals('title', $check->getKeyName());
$this->assertEquals('A Game of Thrones', $check->getKey());
$this->assertEquals('A Game of Thrones', $check->title); It looks like hard coded, however it's being changed when queried within Eloquent, see this function which is being used in this library. If it doesn't work for you, then check Thanks! |
Okay |
For me, it was definitely about specifying the
|
Description:
I am trying to use a custom primary key, but it persists on using _id. After checking similar issues, I found out it posted here #1354 and fixed here #1392.
I checked the code from the library and saw it wasn't changed.
Here is the link to the file from master branch:
https://github.com/jenssegers/laravel-mongodb/blob/master/src/Jenssegers/Mongodb/Query/Builder.php#L189)
Here is the link to the file from merge request:
https://github.com/jenssegers/laravel-mongodb/pull/1392/files
Am I missing something here?
Steps to reproduce
Add the following code to your model:
protected $primaryKey = 'fieldName'
Run
php artisan migrate:refresh
Expected behaviour
I should be able to use a custom primary key.
Actual behaviour
The model uses a hard-coded string
_id
for its primary keyLogs:
The text was updated successfully, but these errors were encountered: