You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we try to update any nested field on Payload UI its overwriting the fields that are not defined on the Payload schema
Background:
Our team is working on the migration from existing CMS (KeystoneJS v4) to Payload, as it is not happening in KeystoneJS
when we migrate our application to Payload this issue will impact our data and can cause other impacts on the application that consuming those datas.
Create a sample data as mentioned below in the collection.
Ex. Sample data in a collection
{
"name": "",
"age": 20,
"address": {
"field1": "YYY",
"field2": "TTTTT",
"field3": "RRRRR"
}
}
Step 3:
On payload UI try to update the field "address.field1" OR "address.field2" and observe the data updated into the collection.
Updating a collection record(Ex. Sample) is overwriting nested fields that present in that db but that are not defined in the payload schema.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Issue Summary:
When we try to update any nested field on Payload UI its overwriting the fields that are not defined on the Payload schema
Background:
Our team is working on the migration from existing CMS (KeystoneJS v4) to Payload, as it is not happening in KeystoneJS
when we migrate our application to Payload this issue will impact our data and can cause other impacts on the application that consuming those datas.
Steps to Reproduce:
Step 1:
Create a collection as below structure
const Sample: CollectionConfig = {
slug: 'sample',
fields: [
{
name: 'name',
type: 'text',
},
{
name: 'address',
type: 'group',
fields: [
{
name: 'field1',
type: 'text',
},
{
name: 'field2',
type: 'text',
},
],
},
],
}
Step 2:
Create a sample data as mentioned below in the collection.
Ex. Sample data in a collection
{
"name": "",
"age": 20,
"address": {
"field1": "YYY",
"field2": "TTTTT",
"field3": "RRRRR"
}
}
Step 3:
On payload UI try to update the field "address.field1" OR "address.field2" and observe the data updated into the collection.
Updating a collection record(Ex. Sample) is overwriting nested fields that present in that db but that are not defined in the payload schema.
Payload Version: ^2.18.3
Payload Plugins:
@payloadcms/db-mongodb
@payloadcms/plugin-relationship-object-ids
Tried Solution
We have tried the flattening module to modify the object before update query gets executed.
This way it will not impact any data that we update.
Refer the below code snippet modified on the file https://github.com/payloadcms/payload/blob/main/packages/db-mongodb/src/updateOne.ts
try {
// TODO: Remove this
if (options.flatten) {
const flat = require('flat')
data = flat.flatten(data);
}
const flat = require('flat');
data = flat.flatten(data);
result = await Model.findOneAndUpdate(query, data, options);
} catch (error) {
}
Also, ‘Options.flatten’ key comes as parameter that we set in the payload config object like below,
db: mongooseAdapter({
url: process.env.MONGO_URI,
flatten: true
})
We would like to know if this solution which we tried is acceptable and has no impact. Any other solutions using a different approach will be helpful.
Feedbacks are appreciated.
Beta Was this translation helpful? Give feedback.
All reactions