Hi,
I'm encountering an issue with the AWS Amplify DataStore save function when updating an object that includes an array property. When I use the DataStore save function to update an object with an array property, and the update input includes a new array value, the array property is not updated correctly and the new value is merged with any existing values.
Example:
Suppose I have an object with an array property called "timeToArrive" that has the value [2, 4]. I use the DataStore save function to update the object, with an update input that includes the new value [1, 1] for the "timeToArrive" property:
const original = await DataStore.query(MyModel, id);
await DataStore.save(MyModel.copyOf(original, updated => {
updated.timeToArrive = [1, 1];
}));
Instead of setting the "timeToArrive" property to [1, 1], the DataStore save function merges the new value with the existing values, resulting in the value [2, 4, 1, 1] for the "timeToArrive" property.
Attempts to fix:
I've tried using different approaches to update the array property, including copying the new values using a for loop or the spread operator, and using a custom resolver to update the object. However, none of these approaches have resolved the issue.
Expected behavior:
I expect the DataStore save function to update the array property correctly, by setting the property to the new value without merging it with any existing values.
Current setup:
AWS Amplify version: 5.0.18
AWS services used: DataStore, DynamoDB
Schema definition for model:
type MyModel @model {
id: ID!
timeToArrive: [Int]
}
Any help or suggestions on how to resolve this issue would be greatly appreciated.