-
Type: New Feature
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: Laravel
-
None
By convention in Eloquent, model's primary key is id. But MongoDB uses _id as primary key (unique index automatically created and can't be removed).
In order to support Laravel packages out of the box, the proposition is to modify the query builder so any query on the "id" field is converted to a query to "_id" field.
$builder->where('id', 123)
becomes
{ _id: 123 }And the same for the result. When _id is returned, the value is converted to id. This is the most tricky part as we don't want to break backward compatibility for projects that refer to _id. But this is a necessary abstraction to match Eloquent design.
Breaking change: using an "id" field distinct from "_id" would not be supported.
Related rejected PR:
- causes
-
PHPORM-243 Rename _id to id in Schema::getColumns introspection
- Closed
- fixes
-
PHPORM-201 laravel-mongodb - Issue #3022: [Feature Request] SessionServiceProvider for database
- Closed
- is depended on by
-
PHPORM-231 Remove MongoFailedJobProvider
- Closed
-
PHPORM-235 Remove custom DatabaseTokenRepository
- Closed
- is related to
-
PHPORM-236 Remove _id from result for query builder
- Closed