dynamodb-toolbox
dynamodb-toolbox copied to clipboard
Problem updating secondary index key
HI there! I'm having problems updating the status of a key on a secondary index, when updating the related attribute.
I've the following entity definition:
gsi2pk: { type: 'string', prefix: 'STATUS#', default: (f) => f.status, onUpdate: true },
status: { type: 'string' },
When I create the entry, the status value is 2, and gsi2pk is STATUS#2 BUT when I update the entry, the new status value is 0, and gsi2pk is still STATUS#2
What I understand on the documentation is that I've to define onUpdate to true to update the default value, but it makes no difference.
Is this a bug or I'm missing something?
I have this problem as well. Any ideas?
@ianpogi5 I bypass the situation updating both values:
userData.status = UserStatus.Deleted;
userData.gsi2pk = UserStatus.Deleted;
but I'll like to know the reason of "onUpdate", and validate if that's an issue or not
I know it's an old issue, but did you try settings the onUpdate attribute when defining gsi2pk ? I had the same problem and it solved it.
Hey @jrodz-ak, thanks for opening this issue and sorry for the delayed response.
@jfreyheit's suggestion is correct, that should fix it for you.
I'll be closing this issue, but feel free to ping me if you need anything 😎 🙏