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

[3.6.5] Model::find with integer keys no longer works after laravel/framework update (v6.18.36 => v6.18.37) #2087

Closed
EligiusSantori opened this issue Aug 29, 2020 · 7 comments
Labels
Needs investigation Need investigation about bugs described in issue

Comments

@EligiusSantori
Copy link

EligiusSantori commented Aug 29, 2020

  • jenssegers/mongodb version: 3.6.4/3.6.5
  • mongodb/mongodb version: 1.4.3/1.6.1/1.7.0
  • laravel/framework version: 6.18.37 (before update 6.18.36)
  • PHP Version: 7.2.24
  • Database Driver & Version: 1.5.3/1.7.5

Description:

After composer update the find() method always returns null for collections with integrer _id.

Also there is difference in \DB::listen behaviour. In old framework version \DB::listen(function($q) { dump($q->sql); }); shows nothing, in new version it shows "profile.find({"_id":"7016278824"},{"limit":1,"typeMap":{"root":"array","document":"array"}})".

Steps to reproduce

  1. MyModel::find($my_id)

Expected behaviour

Should return MyModel instance with data.

Actual behaviour

Returns null.

@EligiusSantori EligiusSantori changed the title [3.6.5] Model::find with integer keys no longer works after laravel/framework update (v6.18.23 => v6.18.37) [3.6.5] Model::find with integer keys no longer works after laravel/framework update (v6.18.36 => v6.18.37) Aug 29, 2020
@divine
Copy link
Contributor

divine commented Sep 10, 2020

Hello,

This PR laravel/framework#34031 broke that.

Possible solution is to define model key type to int.
$keyType = 'int'

Well, this is another breaking change in a minor release.

What do you think @Smolevich ?

@Smolevich Smolevich added the Needs investigation Need investigation about bugs described in issue label Sep 10, 2020
@Smolevich
Copy link
Contributor

Smolevich commented Sep 10, 2020

@EligiusSantori why do you use type string for _id?
From mongodb docs https://docs.mongodb.com/manual/core/document/#the-id-field

@divine
Copy link
Contributor

divine commented Sep 10, 2020

@EligiusSantori why do you use type string for _id?

@Smolevich it's being set by default to string here https://github.com/jenssegers/laravel-mongodb/blob/master/src/Jenssegers/Mongodb/Eloquent/Model.php#L38

@Smolevich
Copy link
Contributor

I mean another thing, _id should value of ObjectId
Test case https://github.com/jenssegers/laravel-mongodb/blob/828e7513f0eeaaa73776724e2f80ee8b66f3bebb/tests/ModelTest.php#L54

@divine
Copy link
Contributor

divine commented Sep 10, 2020

Quite interesting transaction pr also failing https://github.com/jenssegers/laravel-mongodb/pull/1904/checks?check_run_id=1091695716#step:10:22 nothing was changed at all and everything worked like a charm.

@EligiusSantori
Copy link
Author

Well, protected $keyType = 'int'; works. I was sure I tried it.

@divine
Copy link
Contributor

divine commented Sep 14, 2020

Glad it was resolved. Closing.

@divine divine closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs investigation Need investigation about bugs described in issue
Projects
None yet
Development

No branches or pull requests

3 participants