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

Commit 0f1b00df by Mick Hansen

fix fix fix

1 parent e10114fc
......@@ -147,10 +147,7 @@ module.exports = (function() {
return self.primaryKeyAttributes.indexOf(key) !== -1
})
if (this.options.timestamps) {
this.DAO.prototype._timestampAttributes = {
createdAt: Utils._.underscoredIf(this.options.createdAt, this.options.underscored),
updatedAt: Utils._.underscoredIf(this.options.updatedAt, this.options.underscored),
......
......@@ -112,7 +112,7 @@ module.exports = (function() {
}
// If raw, and we're not dealing with includes, just set it straight on the dataValues object
if (options.raw && !(this.options && this.options.include)) {
if (options.raw && !(this.options && this.options.include) && !this._hasBooleanAttributes && !this._hasReadOnlyAttributes) {
if (Object.keys(this.dataValues).length) {
this.dataValues = _.extend(this.dataValues, values)
} else {
......@@ -144,7 +144,7 @@ module.exports = (function() {
}
// If attempting to set read only attributes, return
if (this._hasReadOnlyAttributes && this._isReadOnlyAttribute(key)) {
if (!options.raw && this._hasReadOnlyAttributes && this._isReadOnlyAttribute(key)) {
return
}
......@@ -632,7 +632,6 @@ module.exports = (function() {
key;
values = values && _.clone(values) || {}
// add all passed values to the dao and store the attribute names in this.attributes
if (options.isNewRecord) {
if (this.hasDefaultValues) {
......@@ -644,30 +643,22 @@ module.exports = (function() {
}
if (this.__options.timestamps) {
if (!this.defaultValues[this._timestampAttributes.createdAt]) {
this.dataValues[this._timestampAttributes.createdAt] = Utils.now(this.sequelize.options.dialect)
} else {
this.dataValues[this._timestampAttributes.createdAt] = defaults[this._timestampAttributes.createdAt];
if (defaults[this._timestampAttributes.createdAt]) {
this.dataValues[this._timestampAttributes.createdAt] = Utils.toDefaultValue(defaults[this._timestampAttributes.createdAt]);
delete defaults[this._timestampAttributes.createdAt];
}
if (!this.defaultValues[this._timestampAttributes.updatedAt]) {
this.dataValues[this._timestampAttributes.updatedAt] = Utils.now(this.sequelize.options.dialect)
} else {
this.dataValues[this._timestampAttributes.updatedAt] = defaults[this._timestampAttributes.updatedAt];
if (defaults[this._timestampAttributes.updatedAt]) {
this.dataValues[this._timestampAttributes.updatedAt] = Utils.toDefaultValue(defaults[this._timestampAttributes.updatedAt]);
delete defaults[this._timestampAttributes.updatedAt];
}
if (this.__options.paranoid && !this.defaultValues[this._timestampAttributes.deletedAt]) {
this.dataValues[this._timestampAttributes.deletedAt] = null
} else if (defaults[this._timestampAttributes.deletedAt]) {
this.dataValues[this._timestampAttributes.deletedAt] = defaults[this._timestampAttributes.deletedAt];
if (defaults[this._timestampAttributes.deletedAt]) {
this.dataValues[this._timestampAttributes.deletedAt] = Utils.toDefaultValue(defaults[this._timestampAttributes.deletedAt]);
delete defaults[this._timestampAttributes.deletedAt];
}
}
}
if (Object.keys(defaults).length) {
for (key in defaults) {
if (!values.hasOwnProperty(key)) {
......
......@@ -339,7 +339,7 @@ if (Support.dialectIsMySQL()) {
expectation: "INSERT INTO `myTable` (`name`,`foo`) VALUES ('foo',1),('bar',2);"
}, {
arguments: ['myTable', [{name: 'foo', foo: 1, nullValue: null}, {name: 'bar', nullValue: null}]],
expectation: "INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',NULL);"
expectation: "INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',NULL,NULL);"
}, {
arguments: ['myTable', [{name: 'foo', foo: 1, nullValue: null}, {name: 'bar', foo: 2, nullValue: null}]],
expectation: "INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',2,NULL);",
......@@ -350,7 +350,7 @@ if (Support.dialectIsMySQL()) {
context: {options: {omitNull: true}} // Note: We don't honour this because it makes little sense when some rows may have nulls and others not
}, {
arguments: ['myTable', [{name: 'foo', foo: 1, nullValue: undefined}, {name: 'bar', foo: 2, undefinedValue: undefined}]],
expectation: "INSERT INTO `myTable` (`name`,`foo`,`nullValue`) VALUES ('foo',1,NULL),('bar',2,NULL);",
expectation: "INSERT INTO `myTable` (`name`,`foo`,`nullValue`,`undefinedValue`) VALUES ('foo',1,NULL,NULL),('bar',2,NULL,NULL);",
context: {options: {omitNull: true}} // Note: As above
}, {
arguments: ['myTable', [{name: "foo", value: true}, {name: 'bar', value: false}]],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!