Replies: 2 comments 1 reply
-
This leads to another error when trying to do a
In the error message:
I think this cast error refers to the fact that Payload attempts to slide in the object
|
Beta Was this translation helpful? Give feedback.
-
I don't think we should normalize values as you proposed, as we want the schema to be the source of truth. Instead, if you're changing a field from and, in your case, in order to go from const documents = await Model.collection.find({}, { session }).toArray()
documents.forEach((doc) => {
// from { text: { en : ""}} to { text: ""}
doc.text = doc.text.en
})
// Write everything in 1 db call
await Model.collection.bulkWrite(
documents.map(
(doc) => ({
updateOne: {
filter: { _id: doc._id },
update: {
$set: doc,
},
},
}),
{ session },
),
) I'm converting this to a discussion since it may be helpful for others if they want to change the |
Beta Was this translation helpful? Give feedback.
-
Describe the Bug
When you remove a field that has previously had
localized: true
and a value in the database, the front-end breaks.Link to the code that reproduces this issue
https://github.com/hdodov/test-payload/tree/localize-issues
Reproduction Steps
git clone git@github.com:hdodov/test-payload.git
pnpm docker
to start the projecthttp://localhost:3000/admin/collections/pages
slug
:foo
text
:hello
LOCALIZED=true
in.env
text
field tohello2
LOCALIZED=true
from.env
[object Object]
(not expected)Proposed Solution
Payload should check if fields are coming in the form of an object from the database. It already normalizes
{ en: "content" }
to"content"
when the field is marked as localized. It just has to do this when the field is not marked as localized too. In other words, it should function like this:"foo"
en
"foo"
"foo"
bg
"foo"
{ "en": "foo" }
en
"foo"
{ "en": "foo" }
bg
"foo"
"foo"
en
"foo"
"foo"
bg
"foo"
{ "en": "foo" }
en
"foo"
{ "en": "foo" }
bg
"foo"
{ "bg": "фуу" }
bg
""
…but the current behavior is this:
"foo"
en
"foo"
"foo"
bg
"foo"
{ "en": "foo" }
en
"foo"
{ "en": "foo" }
bg
"foo"
"foo"
en
"foo"
"foo"
bg
"foo"
{ "en": "foo" }
en
{ "en": "foo" }
{ "en": "foo" }
bg
{ "en": "foo" }
{ "bg": "фуу" }
bg
{ "bg": "фуу" }
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
Beta Was this translation helpful? Give feedback.
All reactions