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

Commit 66fb6b67 by Sushant

fix(model): dont use .attributes #4610

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