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

Commit e86089e1 by Mick Hansen

if create is passed a field options, it should only build those values

1 parent 5ccacce4
...@@ -700,21 +700,22 @@ module.exports = (function() { ...@@ -700,21 +700,22 @@ module.exports = (function() {
}.bind(this)) }.bind(this))
} }
DAOFactory.prototype.create = function(values, fieldsOrOptions) { DAOFactory.prototype.create = function(values, options) {
Utils.validateParameter(values, Object, { optional: true }) Utils.validateParameter(values, Object, { optional: true })
Utils.validateParameter(fieldsOrOptions, Object, { deprecated: Array, optional: true, index: 2, method: 'DAOFactory#create' }) Utils.validateParameter(options, Object, { deprecated: Array, optional: true, index: 2, method: 'DAOFactory#create' })
if (fieldsOrOptions instanceof Array) { if (options instanceof Array) {
fieldsOrOptions = { fields: fieldsOrOptions } options = { fields: options }
} }
fieldsOrOptions = Utils._.extend({ options = Utils._.extend({
transaction: null transaction: null
}, fieldsOrOptions || {}) }, options || {})
return this.build(values, { return this.build(values, {
isNewRecord: true isNewRecord: true,
}).save(fieldsOrOptions) attributes: options.fields
}).save(options)
} }
DAOFactory.prototype.findOrInitialize = DAOFactory.prototype.findOrBuild = function (params, defaults, options) { DAOFactory.prototype.findOrInitialize = DAOFactory.prototype.findOrBuild = function (params, defaults, options) {
......
...@@ -717,6 +717,39 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -717,6 +717,39 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('should only set passed fields', function (done) {
var User = this.sequelize.define('User', {
'email': {
type: DataTypes.STRING
},
'name': {
type: DataTypes.STRING
}
})
this.sequelize.sync({force: true}).done(function (err) {
expect(err).not.to.be.ok;
User.create({
name: 'Yolo Bear',
email: 'yolo@bear.com'
}, {
fields: ['name']
}).done(function (err, user) {
expect(err).not.to.be.ok;
expect(user.name).to.be.ok;
expect(user.email).not.to.be.ok;
User.find(user.id).done(function (err, user) {
expect(err).not.to.be.ok;
expect(user.name).to.be.ok;
expect(user.email).not.to.be.ok;
done();
});
});
});
});
describe('enums', function() { describe('enums', function() {
it('correctly restores enum values', function(done) { it('correctly restores enum values', function(done) {
var self = this var self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!