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

Commit 66fb6b67 by Sushant

fix(model): dont use .attributes #4610

1 parent fafe6ac9
......@@ -49,9 +49,7 @@ class Model {
}
// validateIncludedElements should have been called before this method
static _paranoidClause(model, options) {
options = options || {};
static _paranoidClause(model, options = {}) {
// Apply on each include
// This should be handled before handling where conditions because of logic with returns
// otherwise this code will never run on includes of a already conditionable where
......@@ -712,9 +710,7 @@ class Model {
* @return {Model}
*/
static init(attributes, options) { // testhint options:none
options = options || {};
static init(attributes, options = {}) { // testhint options:none
if (!options.sequelize) {
throw new Error('No Sequelize instance passed');
}
......@@ -1074,8 +1070,7 @@ class Model {
}
this.prototype.rawAttributes = this.rawAttributes;
this.prototype.attributes = Object.keys(this.prototype.rawAttributes);
this.prototype._isAttribute = _.memoize(key => this.prototype.attributes.indexOf(key) !== -1);
this.prototype._isAttribute = key => this.prototype.rawAttributes.hasOwnProperty(key);
// Primary key convenience constiables
this.primaryKeyAttributes = Object.keys(this.primaryKeys);
......@@ -1085,7 +1080,7 @@ class Model {
}
this._hasPrimaryKeys = this.primaryKeyAttributes.length > 0;
this._isPrimaryKey = _.memoize(key => this.primaryKeyAttributes.indexOf(key) !== -1);
this._isPrimaryKey = key => this.primaryKeyAttributes.includes(key);
}
/**
......@@ -2262,7 +2257,7 @@ class Model {
}).then(() => {
// Map field names
const updatedDataValues = _.pick(instance.dataValues, Object.keys(instance._changed));
const insertValues = Utils.mapValueFieldNames(instance.dataValues, instance.attributes, this);
const insertValues = Utils.mapValueFieldNames(instance.dataValues, Object.keys(instance.rawAttributes), this);
const updateValues = Utils.mapValueFieldNames(updatedDataValues, options.fields, this);
const now = Utils.now(this.sequelize.options.dialect);
......@@ -3578,7 +3573,7 @@ class Model {
}
if (options.silent === true && !(this.isNewRecord && this.get(updatedAtAttr, {raw: true}))) {
// UpdateAtAttr might have been added as a result of Object.keys(Model.attributes). In that case we have to remove it again
// UpdateAtAttr might have been added as a result of Object.keys(Model.rawAttributes). In that case we have to remove it again
_.remove(options.fields, val => val === updatedAtAttr);
updatedAtAttr = false;
}
......
......@@ -76,7 +76,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return this.User.find({where: {username: 'John'}}).then(john => {
return john.getTasks();
}).then(tasks => {
tasks[0].attributes.forEach(attr => {
Object.keys(tasks[0].rawAttributes).forEach(attr => {
expect(tasks[0]).to.have.property(attr);
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!