Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix array casts as string #3418

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

Open
hans-thomas wants to merge 3 commits into mongodb:5.x
base: 5.x
Choose a base branch
Loading
from hans-thomas:Model-array-cast-saved-as-string-#3306

Conversation

Copy link
Contributor

@hans-thomas hans-thomas commented Jun 29, 2025

Hello everyone :)
As described here #3306, when casting an array attribute as array, it will save as a JSON-encoded string.
In this PR, I prevent casting an array to a string.

Copy link
Contributor Author

Hi @paulinevos, could you please review my PR?

@alcaeus alcaeus requested review from alcaeus and removed request for paulinevos July 23, 2025 07:52
Copy link
Member

alcaeus commented Jul 23, 2025

@hans-thomas in general, the changes look good. I am a little bit worried about the BC impact of this change, as any fields that previously used an array cast will have been saved as JSON string and won't be read successfully in future. To mitigate this, we need to do two things:

  • Create a new json cast that people should use instead of array (ignore if something like that already exists in Laravel)
  • Emit a deprecation notice in isJsonCastable if someone is using an array cast. If they are, we should tell them to either use the json cast if they want to store the array as a JSON-encoded string, or to remove the array cast if they want to store it as an array. We can then remove that deprecation notice in the next major version.

With the _id vs. id issue fresh in my mind, I don't want to create another data migration problem for users, so we need to give people the option to retain the old behaviour, no matter how useless it may be in MongoDB.

hans-thomas reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@alcaeus alcaeus Awaiting requested review from alcaeus

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /