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

Overriding $primaryKey does not work with find($id) #1354

Closed
jim5359 opened this issue Nov 3, 2017 · 3 comments · Fixed by #1392
Closed

Overriding $primaryKey does not work with find($id) #1354

jim5359 opened this issue Nov 3, 2017 · 3 comments · Fixed by #1392

Comments

@jim5359
Copy link
Contributor

jim5359 commented Nov 3, 2017

I get the error:
Undefined index: myId in /Jenssegers/Mongodb/Query/Builder.php:575

It looks like the Builder class is hard-coded to expect the key as _id:

return $sequence == '_id' ? $result->getInsertedId() : $values[$sequence];

This causes problems when doing a find($id) when you've modified the primaryKey to be something else in the model class.

public $primaryKey = 'myId';

I'm using the latest master version using PHP7 and Mongo 3.4

@jim5359
Copy link
Contributor Author

jim5359 commented Nov 3, 2017

Actually, I tried hacking that file and got rid of the error, but now it's just ignoring the $primaryKey setting. So looks like this capability is broken in the latest version.

@jim5359 jim5359 changed the title Undefined index: warehouseId in /Jenssegers/Mongodb/Query/Builder.php:575 Overriding $primaryKey does not work with find() Nov 16, 2017
@jim5359 jim5359 changed the title Overriding $primaryKey does not work with find() Overriding $primaryKey does not work with find($id) Nov 16, 2017
@StevePorter92
Copy link
Contributor

@jim5359 the fix in #1392 should solve your problem :)

@jim5359
Copy link
Contributor Author

jim5359 commented Dec 20, 2017

Awesome @DMNSteve !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants