-
-
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
Does Dynamoose support saving non attribute data? #107
Comments
Dynamoose doesn't support saving data not defined in the schema. It could be done but would required modifying Something like the changes below. If you have time to test and document, I would be happy to merge a PR. Schema.prototype.toDynamo = function(model) {
var dynamoObj = {};
for(var name in model) {
var attr = this.attributes[name];
if(!attr & this.options.saveUnknown) {
attr = Attribute.create(this, name, Object);
this.attributes[name] = attr;
}
if(attr) {
attr.setDefault(model);
var dynamoAttr = attr.toDynamo(model[name], undefined, model);
if(dynamoAttr) {
dynamoObj[attr.name] = dynamoAttr;
}
}
}
debug('toDynamo: %s', JSON.stringify(dynamoObj) );
return dynamoObj;
};
Schema.prototype.parseDynamo = function(model, dynamoObj) {
for(var name in dynamoObj) {
var attr = this.attributes[name];
if(!attr & this.options.saveUnknown) {
attr = Attribute.create(this, name, Object);
this.attributes[name] = attr;
}
if(attr) {
var attrVal = attr.parseDynamo(dynamoObj[name]);
if(attrVal !== undefined && attrVal !== null){
model[name] = attrVal;
}
}
}
debug('parseDynamo: %s',JSON.stringify(model));
return dynamoObj;
}; |
Thanks! I'll have a look later next week. |
I'm assuming I'd also have to modify Model.js Operations.getUpdateExpression ? |
Upon some testing, it seems this involves a bigger change. Hit problems where the data was not injected into the putSet, or were new attributes being created on the fly. |
I don't think any changes are needed in the The if(!attr & this.options.saveUnknown) {
attr = Attribute.create(this, name, Object);
this.attributes[name] = attr;
} If you push your the changes to your fork, I would be happy to look them over and see if i can spot the issue. |
Bump. Ran into this same issue. This would be an awesome addition. |
I have defined some basic attributes of the model, for example.
But when I do something like
info, never gets saved. How can I save data that's not defined in the schema?
The text was updated successfully, but these errors were encountered: