tywalch / electrodb

A DynamoDB library to ease the use of modeling complex hierarchical relationships and implementing a Single Table Design while keeping your query code readable.
MIT License
956 stars 58 forks source link

Update nested Map value using set() method. #371

Closed oise closed 3 months ago

oise commented 3 months ago

Describe the bug When I try to use .set() to update a nested map, the entire map gets replaced with the new value. This might be dueSee electroDb Playground link.

ElectroDB Version 2.13.1

ElectroDB Playground Link Link

Expected behavior I think the generated UpdateExpression should be "UpdateExpression": "SET #comments.user = :comments_u0, ....

I am currently only able to update a nested map without losing the previous data by using .data()

tywalch commented 3 months ago

Hi @oise!

The set method works on "root" attributes, so the behavior you describe is expected. To accomplish what you're doing however can be accomplished via the data method. Here is an example of how you would accomplish that 👍

oise commented 3 months ago

Thanks for clarifying @tywalch.