Skip to content

Mapping of id to _id in nested or embedded documents is breaking for many and should come with the ability to disable globally #3350

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

Closed
benmartin88 opened this issue Apr 12, 2025 · 1 comment

Comments

@benmartin88
Copy link

  • Laravel-mongodb Version: ^5.1.1
  • PHP Version: 8.2.27
  • Database Driver & Version:

Description: Since the change was introduced to cast id to _id in nested and embedded documents, any platforms that were using an id field anywhere in a nested / embedded document will find much of their model logic impacted negatively. As Laravel didn't support (or not very well) the standard concept for creating models for nested docs as you would with SQL and tables / relations, it would be fairly normal to have a field in any of the documents as id.

Steps to reproduce

  1. Save any model that has a nested document with a field named id and you will find it saved as _id

Expected behaviour

Whilst I understand this is now expected behaviour based on the update introduced, it should be something that can be disabled globally. The work required to cast this on a per model basis with deeply nested objects is quite large, and should not be an acceptable solution.

Actual behaviour

As above

A global override should be added to allow people to take advantage of the updates without such large breaking changes.

@bisht2050
Copy link
Contributor

This is a duplicate of #3184

This feature is available in v5.3.0
Check Documentation for details

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

No branches or pull requests

2 participants