Model can't delete when rangeKey is createdAt
See original GitHub issueSummary:
When call Model.delete or model.delete, it happens error and can’t delete.
Code sample:
Schema
schema: {
id: { type: String, hashKey: true },
createdAt: {
rangeKey: true,
},
schemaOptions: {
timestamps: true,
},
}
General
Error happens when call
Model.delete({id:'aaaa',createdAt: 1553137260667})
or
cosnt model = await Model.get({id:'aaaa',createdAt:1553137260667})
model.delete()
Current output and behavior:
TypeError: Cannot read property 'updateTimestamps' of undefined
at Attribute.toDynamo (/node_modules/dynamoose/dist/Attribute.js:390:30)
at NewModel.Model.delete (/node_modules/dynamoose/dist/Model.js:1007:65)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
Maybe, in Attribute.js
Attribute.prototype.toDynamo = async function (val, noSet, model, options) {
...
if (isTimestamp && options.updateTimestamps === false) {
runSet = false;
}
if (isExpires && options.updateExpires === true) {
val = await this.default();
runSet = true;
}
this will change as below?
Attribute.prototype.toDynamo = async function (val, noSet, model, options) {
...
if (isTimestamp && options && options.updateTimestamps === false) {
runSet = false;
}
if (isExpires && options && options.updateExpires === true) {
val = await this.default();
runSet = true;
}
Environment:
Node.js version (node -v
): 8.10
Dynamoose version: 1.7.2
Dynamoose Plugins:
- Yes, I believe that one or multiple 3rd party Dynamoose plugins are effecting this issue
- No, I believe this issue is independent of any 3rd party Dynamoose plugins I’m using
- Unknown, I’m unsure if Dynamoose plugins are effecting this issue
- I am not using any Dynamoose plugins
Other information (if applicable):
Type (select 1):
- Bug report
- Feature suggestion
- Question
- Other suggestion
- Something not listed here
Other:
- I have read through the Dynamoose documentation before posting this issue
- I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
- I have searched the internet and Stack Overflow to ensure this issue hasn’t been raised or answered before
- I have tested the code provided and am confident it doesn’t work as intended
- I have ensured that all of my plugins that I’m using with Dynamoose are listed above
- I have filled out all fields above
- I am running the latest version of Dynamoose
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Dynamoose - cannot query and where with 2 keys
I suspect createdAt is not a range key of your table / index. You need to either do .filter('createdAt').ge(date) or modify your table ......
Read more >API (GraphQL) - Index your data with keys - Amplify Docs
The @key directive makes it simple to configure custom index structures for @model types. - AWS Amplify Docs.
Read more >DynamoDB Keys - Everything You Need To Know - Dynobase
Learn about different DynamoDB keys (primary simple/composite key, local/global secondary key) + when and how you can use them.
Read more >Improving data access with secondary indexes
Local secondary indexes are created at the same time that you create a table. You cannot add a local secondary index to an...
Read more >dynogels - npm
Simplified data modeling and mapping to DynamoDB types ... You can configure dynogels to automatically add createdAt and updatedAt timestamp ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Unfortunately that did not work for me either. Ended up doing the following:
@dolsem The issue was inactive for a long period of time, and there was a proposed solution at the time the issue was closed. Reopening now. I haven’t been able to confirm this bug or anything tho. PRs are always welcome.