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
Describe the bug
Everything I am going to describe revolves around how to handle key formatting with composite attributes are not required at the schema level. And I believe there are some inconsistencies with how it currently works.
Note that Electro created the GSI keys using an empty string for the role attribute. I find this interesting but not necessarily problematic.
Taking the previous example, if I were to add another attribute to the composite array that contains role and if this attribute happens to be a required attribute at the schema level, if we were to create an item without passing the role attribute but did pass the other attribute in that composite array, Electro will throw an error.
running users.create({ id: '123', birth_date: '2024-01-01' }).go() will throw
Incomplete composite attributes: Without the composite attributes "role" the following access patterns cannot be updated: "byRole". If a composite attribute is readOnly and cannot be set, use the 'composite' chain method on update to supply the value for key formatting purposes.
ElectroDB Version
4.0.1
Expected behavior
To be honest, I am not sure what the expected behavior should be. Allowing optional attributes to be specified in the composite field poses some challenges like during partial updates.
For example, let's say we were to allow optional attributes in indexes. And let's say that if an optional field is not passed during creation, we don't format that key (which is not how it works currently).
So taking the second example, we would create a user without passing a role and passing birth_date. Following what I said, we won't format the GSI key.
What is the user's expectation when we do a partial update on a user and only update the birth_date attribute without specifying the role attribute?
do we throw an error because we didn't provide all the composite attributes? but what if the role does not exist on the saved item and we want to keep it as such?
Not sure how to come up with a solution that solves all the use cases.
What I am doing for now is only using required attributes in index composite fields and passing an empty string for example for fields that would normally be optional.
The text was updated successfully, but these errors were encountered:
Describe the bug
Everything I am going to describe revolves around how to handle key formatting with composite attributes are not required at the schema level. And I believe there are some inconsistencies with how it currently works.
running
users.create({ id: '123' }).go()
will create the following dynamo params:Note that Electro created the GSI keys using an empty string for the
role
attribute. I find this interesting but not necessarily problematic.role
and if this attribute happens to be a required attribute at the schema level, if we were to create an item without passing therole
attribute but did pass the other attribute in that composite array, Electro will throw an error.playground
running
users.create({ id: '123', birth_date: '2024-01-01' }).go()
will throwElectroDB Version
4.0.1
Expected behavior
To be honest, I am not sure what the expected behavior should be. Allowing optional attributes to be specified in the composite field poses some challenges like during partial updates.
For example, let's say we were to allow optional attributes in indexes. And let's say that if an optional field is not passed during creation, we don't format that key (which is not how it works currently).
So taking the second example, we would create a user without passing a
role
and passingbirth_date
. Following what I said, we won't format the GSI key.What is the user's expectation when we do a partial update on a
user
and only update thebirth_date
attribute without specifying therole
attribute?do we throw an error because we didn't provide all the composite attributes? but what if the
role
does not exist on the saved item and we want to keep it as such?Not sure how to come up with a solution that solves all the use cases.
What I am doing for now is only using required attributes in index composite fields and passing an empty string for example for fields that would normally be optional.
The text was updated successfully, but these errors were encountered: