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

[11.x] Explicit id field when reading session from database #52079

Closed
wants to merge 1 commit into from

Conversation

GromNaN
Copy link
Contributor

@GromNaN GromNaN commented Jul 10, 2024

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 package mongodb/laravel-mongodb.

The ID field name is hardcoded in the class DatabaseSessionHandler,

return $this->getQuery()->insert(Arr::set($payload, 'id', $sessionId));

return $this->getQuery()->where('id', $sessionId)->update($payload);

$this->getQuery()->where('id', $sessionId)->delete();

But for the read method, the class relies on Query\Builder::find implementation:
public function find($id, $columns = ['*'])
{
return $this->where('id', '=', $id)->first($columns);
}

MongoDB's default ID field is _id, so we overloaded Query\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-L231

The issue is that documents are stored by DatabaseSessionHandler with the field id, but queried with the field _id.
I hope this PR can be accepted to fix mongodb/laravel-mongodb#3022.

@GromNaN GromNaN changed the title Explicit id field when reading session from database [11.x] Explicit id field when reading session from database Jul 10, 2024
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

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 this pull request may close these issues.

[Feature Request] SessionServiceProvider for database
2 participants