不要怂,就是干,撸起袖子干!

Commit cde5de93 by Mick Hansen

refactor(instance): .save(fields, options) -> .save(options)

1 parent 49b6352f
Showing with 7 additions and 8 deletions
...@@ -92,12 +92,12 @@ It's also possible to define which attributes should be saved when calling`save` ...@@ -92,12 +92,12 @@ It's also possible to define which attributes should be saved when calling`save`
```js ```js
task.title = 'foooo' task.title = 'foooo'
task.description = 'baaaaaar' task.description = 'baaaaaar'
task.save(['title']).success(function() { task.save({fields: ['title']}).then(function() {
// title will now be 'foooo' but description is the very same as before // title will now be 'foooo' but description is the very same as before
}) })
   
// The equivalent call using updateAttributes looks like this: // The equivalent call using updateAttributes looks like this:
task.updateAttributes({ title: 'foooo', description: 'baaaaaar'}, ['title']).success(function() { task.updateAttributes({ title: 'foooo', description: 'baaaaaar'}, {fields: ['title']}).success(function() {
// title will now be 'foooo' but description is the very same as before // title will now be 'foooo' but description is the very same as before
}) })
``` ```
......
...@@ -442,22 +442,21 @@ module.exports = (function() { ...@@ -442,22 +442,21 @@ module.exports = (function() {
* On success, the callback will be called with this instance. On validation error, the callback will be called with an instance of `Sequelize.ValidationError`. * On success, the callback will be called with this instance. On validation error, the callback will be called with an instance of `Sequelize.ValidationError`.
* This error will have a property for each of the fields for which validation failed, with the error message for that field. * This error will have a property for each of the fields for which validation failed, with the error message for that field.
* *
* @param {Array} [fields] An optional array of strings, representing database columns. If fields is provided, only those columns will be validation and saved.
* @param {Object} [options] * @param {Object} [options]
* @param {Object} [options.fields] An alternative way of setting which fields should be persisted * @param {Object} [options.fields] An optional array of strings, representing database columns. If fields is provided, only those columns will be validation and saved.
* @param {Boolean} [options.silent=false] If true, the updatedAt timestamp will not be updated. * @param {Boolean} [options.silent=false] If true, the updatedAt timestamp will not be updated.
* @param {Transaction} [options.transaction] * @param {Transaction} [options.transaction]
* *
* @return {Promise<this|Errors.ValidationError>} * @return {Promise<this|Errors.ValidationError>}
*/ */
Instance.prototype.save = function(fieldsOrOptions, options) { Instance.prototype.save = function(options, deprecated) {
if (fieldsOrOptions instanceof Array) { if (options instanceof Array) {
fieldsOrOptions = { fields: fieldsOrOptions }; options = { fields: options };
} }
options = Utils._.extend({ options = Utils._.extend({
hooks: true hooks: true
}, options, fieldsOrOptions); }, options, deprecated);
if (!options.fields) { if (!options.fields) {
options.fields = Object.keys(this.Model.attributes); options.fields = Object.keys(this.Model.attributes);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!