Skip to content

Commit

Permalink
fix: rollback PR #13951 in v6 (#14004)
Browse files Browse the repository at this point in the history
  • Loading branch information
ephys committed Jan 25, 2022
1 parent fd42687 commit 1882f3c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 82 deletions.
14 changes: 8 additions & 6 deletions lib/model.js
Expand Up @@ -314,7 +314,7 @@ class Model {

/**
* Returns the attributes of the model.
*
*
* @returns {object|any}
*/
static getAttributes() {
Expand Down Expand Up @@ -1916,7 +1916,8 @@ class Model {
}

// Bypass a possible overloaded findOne
return await Model.findOne.call(this, options);
// note: in v6, we don't bypass overload https://github.com/sequelize/sequelize/issues/14003
return await this.findOne(options);
}

/**
Expand Down Expand Up @@ -1950,9 +1951,10 @@ class Model {
}

// Bypass a possible overloaded findAll.
return await Model.findAll.call(this, (_.defaults(options, {
plain: true,
})));
// note: in v6, we don't bypass overload https://github.com/sequelize/sequelize/issues/14003
return await this.findAll(_.defaults(options, {
plain: true
}));
}

/**
Expand Down Expand Up @@ -2569,7 +2571,7 @@ class Model {
* @param {boolean} [options.hooks=true] Run before / after bulk create hooks?
* @param {boolean} [options.individualHooks=false] Run before / after create hooks for each individual Instance? BulkCreate hooks will still be run if options.hooks is true.
* @param {boolean} [options.ignoreDuplicates=false] Ignore duplicate values for primary keys? (not supported by MSSQL or Postgres < 9.5)
* @param {Array} [options.updateOnDuplicate] Fields to update if row key already exists (on duplicate key update)? (only supported by MySQL, MariaDB, SQLite >= 3.24.0 & Postgres >= 9.5).
* @param {Array} [options.updateOnDuplicate] Fields to update if row key already exists (on duplicate key update)? (only supported by MySQL, MariaDB, SQLite >= 3.24.0 & Postgres >= 9.5).
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
Expand Down
42 changes: 0 additions & 42 deletions test/unit/model/find-by-pk.test.js

This file was deleted.

34 changes: 0 additions & 34 deletions test/unit/model/find-one.test.js
Expand Up @@ -105,39 +105,5 @@ describe(Support.getTestDialectTeaser('Model'), () => {
await Model.findOne({ where: { unique1: 42 } });
expect(this.stub.getCall(0).args[0]).to.be.an('object').to.have.property('limit');
});
it('should call internal findAll() method if findOne() is overridden', async () => {
const Model = current.define('model', {
unique1: {
type: DataTypes.INTEGER,
unique: 'unique',
},
unique2: {
type: DataTypes.INTEGER,
unique: 'unique',
},
});
Model.findAll = sinon.stub();

await Model.findOne();
Model.findAll.should.not.have.been.called;
Sequelize.Model.findAll.should.have.been.called;
});
it('should call internal findAll() method if findOne() is overridden', async () => {
const Model = current.define('model', {
unique1: {
type: DataTypes.INTEGER,
unique: 'unique',
},
unique2: {
type: DataTypes.INTEGER,
unique: 'unique',
},
});
Model.findAll = sinon.stub();

await Model.findOne();
Model.findAll.should.not.have.been.called;
Sequelize.Model.findAll.should.have.been.called;
});
});
});

0 comments on commit 1882f3c

Please sign in to comment.