-
-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated attributes: Pass current model to attribute default function. #124
Comments
Passing the model sounds like a great idea. Want to submit it as a PR? Not sure I follow the forceDefault. Would this overwrite the value with the default, regardless of if there's currently a value? Also, default would not be in the index. It should be applied directly to the attribute: const schema = {
_id: String,
country: String,
state: String,
surName: String,
surNameIndex: {
index: true,
default: model => {
return `${model.country}_${model.state}_${model.surName}`;
}
}
} |
Yep. I'll submit the pr.
Yes, force default would always overwrite the value on attribute value on
the model. The idea here is to have a field that is flagged as an index and
remains up to date. This would help keep the index updated based on the
previous example.
On Tue, Apr 11, 2017, 6:41 PM Brandon Goode <notifications@github.com> wrote:
Passing the model sounds like a great idea. Want to submit it as a PR?
Not sure I follow the forceDefault. Would this overwrite the value with the
default, regardless of if there's currently a value?
Also, default would not be in the index. It should be applied directly to
the attribute:
const schema = {
_id: String,
country: String,
state: String,
surName: String,
surNameIndex: {
index: true,
default: model => {
return `${model.country}_${model.state}_${model.surName}`;
}
}
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#124 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABq9MiRJOcepFwaakpixV8r0DSeMv17tks5rvCvhgaJpZM4M5kiY>
.
|
Is the idea for the generated value be stored in the DynamoDB table? |
@troyswanson Yes. |
Would it be possible for something like #120 (comment) to be included with this? |
That looks out of scope of what I'm trying to accomplish here. |
Fair enough. |
It would be awesome if we could specify a default function for an attribute and get the current instance of the model as a parameter. That would allow us to populate the secondary index in a better way.
Seems passing the model here would do the trick:
https://github.com/automategreen/dynamoose/blob/108fcaa91fc1785dc4d3623231f6b7a16f877dc4/lib/Attribute.js#L280
More generically however, having a forceDefault boolean for the attribute to ensure the default is applied every time would also be useful. This would ensure the secondary index data is properly updated when the data is persisted.
The text was updated successfully, but these errors were encountered: