Skip to content
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

Consider showing an example of constructing Model.update in readme. #50

Open
elipeters opened this issue Apr 5, 2018 · 2 comments
Open

Comments

@elipeters
Copy link

elipeters commented Apr 5, 2018

I found the constructor...

1058 Model.update(values, vogelsOptions, function (err, res) { ... });

So values is my table map and I get an error if I don't include my primary key which is odd considering that this is not likely to change. The error is not useful as it is 'undefined'.
ValidationException: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes undefined

...and vogelsOptions would be my search criteria as eg. {where:{id:user.id}}

...eg

User.update(params,{where:{id:req.user.id}}).exec(function(err, res){
  //do something
});

...and yet I'm still not writing to the table. Can anyone show me a working example?

@elipeters
Copy link
Author

elipeters commented Apr 5, 2018

4 mins later I manage to answer my question... the "odd" part was the key. Swapping the two inputs makes more sense.

User.update({id:req.user.id},params).exec(function(err, res){
  //do something
});

What threw me was

1055 var vogelsOptions = !_.isEmpty(options.where) ? { expected: options.where } : {};

@elipeters
Copy link
Author

...also you must return the update for it to execute.

User.update({id:req.user.id},params); //doesn't update 

User.update({id:req.user.id},params).exec(function(err,users){
    //update as expected 
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant