[11.x] Explicit id
field when reading session from database
#52079
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I would like to fix the database query used by the
DatabaseSessionHandler
in order to make it compatible with a MongoDB connection provided by the packagemongodb/laravel-mongodb
.The ID field name is hardcoded in the class
DatabaseSessionHandler
,framework/src/Illuminate/Session/DatabaseSessionHandler.php
Line 158 in 68e88bb
framework/src/Illuminate/Session/DatabaseSessionHandler.php
Line 173 in 68e88bb
framework/src/Illuminate/Session/DatabaseSessionHandler.php
Line 269 in 68e88bb
But for the read method, the class relies on
Query\Builder::find
implementation:framework/src/Illuminate/Database/Query/Builder.php
Lines 2899 to 2902 in 68e88bb
MongoDB's default ID field is
_id
, so we overloadedQuery\Builder::find()
in the MongoDB package. The query uses the_id
field, this is necessary for Eloquent models with MongoDB: https://github.com/mongodb/laravel-mongodb/blob/f654b833d31ec3cac96887e6db61c5fef4f68b4a/src/Query/Builder.php#L228-L231The issue is that documents are stored by
DatabaseSessionHandler
with the fieldid
, but queried with the field_id
.I hope this PR can be accepted to fix mongodb/laravel-mongodb#3022.