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

update/delete single row #111

Closed
GoNode5 opened this issue Apr 10, 2013 · 4 comments
Closed

update/delete single row #111

GoNode5 opened this issue Apr 10, 2013 · 4 comments

Comments

@GoNode5
Copy link

GoNode5 commented Apr 10, 2013

Mysql: what would be the code for updating an row:
I see one example;
people[0].save(function (err) {
// err.msg = "under-age";
});
DML: Driver.prototype.update
DML: Driver.prototype.remove

not sure wich way to go?

@dxg
Copy link
Collaborator

dxg commented Apr 10, 2013

dm.models.person.get(1, function(err, item) {
  item.name = 'Jacque';
  item.save( ...
});

For changing many attributes at once I used: _.extend(item, attributes);

There is no publicly exposed item.update(attrs, cb) method.

Definitely on the todo list..

@dresende
Copy link
Owner

It's an easy function to do. About the "delete single row" issue, you can just do:

item.remove(function (err) { // callback optional
    if (!err) console.log("removed!");
});

@dresende
Copy link
Owner

Instead of creating another method in every instance (which could conflict with properties names and we want to avoid it), I changed .save() to support the following different options.

item.save(); // just save, no callback given
item.save(cb); // save with callback
item.save({ name: "Jacque" }); // update 'name', save, no callback given
item.save({ name: "Jacque" }, cb); // update 'name', save with callback

@dxg
Copy link
Collaborator

dxg commented Apr 10, 2013

Makes sense. Nice.

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

No branches or pull requests

3 participants