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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the Bug
When you remove a field that has previously had
localized: trueand 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 [email protected]:hdodov/test-payload.gitpnpm dockerto start the projecthttp://localhost:3000/admin/collections/pagesslug:footext:hello{ "_id" : ObjectId("672efe5985ce4bd7437d6d7c"), "slug" : "foo", "text" : "hello", "createdAt" : ISODate("2024-11-09T06:16:57.505+0000"), "updatedAt" : ISODate("2024-11-09T06:16:57.505+0000"), "__v" : NumberInt(0) }LOCALIZED=truein.envtextfield tohello2{ "_id" : ObjectId("672efe5985ce4bd7437d6d7c"), "slug" : "foo", - "text" : "hello", + "text" : { + "en" : "hello2" + }, "createdAt" : ISODate("2024-11-09T06:16:57.505+0000"), "updatedAt" : ISODate("2024-11-09T06:36:22.517+0000"), "__v" : NumberInt(0) }LOCALIZED=truefrom.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