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

Commit 2123ee51 by Jozef Hartinger Committed by Sushant

fix(model): pick own properties for attributes / getters / sanitizors (fix #8719) (#8720)

1 parent 5c3b4e3b
......@@ -184,7 +184,7 @@ class Query extends AbstractQuery {
});
}
return tableTypes[name]
return tableTypes.hasOwnProperty(name)
? query.applyParsers(tableTypes[name], value)
: value;
});
......
......@@ -3139,7 +3139,7 @@ class Model {
options = options || {};
if (key) {
if (this._customGetters[key] && !options.raw) {
if (this._customGetters.hasOwnProperty(key) && !options.raw) {
return this._customGetters[key].call(this, key, options);
}
if (options.plain && this._options.include && this._options.includeNames.indexOf(key) !== -1) {
......@@ -3298,7 +3298,7 @@ class Model {
}
// If there's a data type sanitizer
if (!(value instanceof Utils.SequelizeMethod) && this.constructor._dataTypeSanitizers[key]) {
if (!(value instanceof Utils.SequelizeMethod) && this.constructor._dataTypeSanitizers.hasOwnProperty(key)) {
value = this.constructor._dataTypeSanitizers[key].call(this, value, options);
}
......
......@@ -71,6 +71,31 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
it('allows for an attribute to be called "toString"', function () {
const Person = this.sequelize.define('person', {
name: Sequelize.STRING,
nick: Sequelize.STRING
}, {
timestamps: false
});
return this.sequelize.sync({force: true})
.then(() => Person.create({name: 'Jozef', nick: 'Joe'}))
.then(() => Person.findOne({
attributes: [
'nick',
['name', 'toString']
],
where: {
name: 'Jozef'
}
}))
.then(person => {
expect(person.dataValues['toString']).to.equal('Jozef');
expect(person.get('toString')).to.equal('Jozef');
});
});
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!