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

Commit 71e3b59f by Benji Koltai Committed by Sushant

fix(model): check for own property when overriding association mixins (#9952) (#9953)

1 parent 214c791b
...@@ -57,7 +57,7 @@ function mixinMethods(association, obj, methods, aliases) { ...@@ -57,7 +57,7 @@ function mixinMethods(association, obj, methods, aliases) {
for (const method of methods) { for (const method of methods) {
// don't override custom methods // don't override custom methods
if (!obj[association.accessors[method]]) { if (!obj.hasOwnProperty(association.accessors[method])) {
const realMethod = aliases[method] || method; const realMethod = aliases[method] || method;
obj[association.accessors[method]] = function() { obj[association.accessors[method]] = function() {
......
...@@ -124,6 +124,16 @@ describe(Support.getTestDialectTeaser('hasMany'), () => { ...@@ -124,6 +124,16 @@ describe(Support.getTestDialectTeaser('hasMany'), () => {
expect(user[method]()).to.be.a('function'); expect(user[method]()).to.be.a('function');
}); });
}); });
it('should not override attributes', () => {
const Project = current.define('Project', {hasTasks: DataTypes.BOOLEAN});
Project.hasMany(Task);
const company = Project.build();
expect(company.hasTasks).not.to.be.a('function');
});
}); });
describe('get', () => { describe('get', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!