MCPcopy
hub / github.com/sequelize/sequelize / findAll

Method findAll

src/model.js:1744–1841  ·  view source on GitHub ↗

* Search for multiple instances. * * @example Simple search using AND and = * Model.findAll({ * where: { * attr1: 42, * attr2: 'cake' * } * }) * * # WHERE attr1 = 42 AND attr2 = 'cake' * * @example Using greater than, less t

(options)

Source from the content-addressed store, hash-verified

1742 * @returns {Promise<Array<Model>>}
1743 */
1744 static async findAll(options) {
1745 if (options !== undefined && !_.isPlainObject(options)) {
1746 throw new sequelizeErrors.QueryError('The argument passed to findAll must be an options object, use findByPk if you wish to pass a single primary key value');
1747 }
1748
1749 if (options !== undefined && options.attributes) {
1750 if (!Array.isArray(options.attributes) && !_.isPlainObject(options.attributes)) {
1751 throw new sequelizeErrors.QueryError('The attributes option must be an array of column names or an object');
1752 }
1753 }
1754
1755 this.warnOnInvalidOptions(options, Object.keys(this.rawAttributes));
1756
1757 const tableNames = {};
1758
1759 tableNames[this.getTableName(options)] = true;
1760 options = Utils.cloneDeep(options);
1761
1762 // Add CLS transaction
1763 if (options.transaction === undefined && this.sequelize.constructor._cls) {
1764 const t = this.sequelize.constructor._cls.get('transaction');
1765 if (t) {
1766 options.transaction = t;
1767 }
1768 }
1769
1770 _.defaults(options, { hooks: true });
1771
1772 // set rejectOnEmpty option, defaults to model options
1773 options.rejectOnEmpty = Object.prototype.hasOwnProperty.call(options, 'rejectOnEmpty')
1774 ? options.rejectOnEmpty
1775 : this.options.rejectOnEmpty;
1776
1777 this._injectScope(options);
1778
1779 if (options.hooks) {
1780 await this.runHooks('beforeFind', options);
1781 }
1782 this._conformIncludes(options, this);
1783 this._expandAttributes(options);
1784 this._expandIncludeAll(options);
1785
1786 if (options.hooks) {
1787 await this.runHooks('beforeFindAfterExpandIncludeAll', options);
1788 }
1789 options.originalAttributes = this._injectDependentVirtualAttributes(options.attributes);
1790
1791 if (options.include) {
1792 options.hasJoin = true;
1793
1794 this._validateIncludedElements(options, tableNames);
1795
1796 // If we're not raw, we have to make sure we include the primary key for de-duplication
1797 if (
1798 options.attributes
1799 && !options.raw
1800 && this.primaryKeyAttribute
1801 && !options.attributes.includes(this.primaryKeyAttribute)

Callers 15

findOneMethod · 0.95
findAndCountAllMethod · 0.95
destroyMethod · 0.95
restoreMethod · 0.95
updateMethod · 0.95
customFnFunction · 0.80
cls.test.jsFile · 0.80
executeFunction · 0.80
data-types.test.jsFile · 0.80
testSuccessFunction · 0.80
utils.test.jsFile · 0.80
model.test.jsFile · 0.80

Calls 12

warnOnInvalidOptionsMethod · 0.95
getTableNameMethod · 0.95
_injectScopeMethod · 0.95
_conformIncludesMethod · 0.95
_expandAttributesMethod · 0.95
_expandIncludeAllMethod · 0.95
_paranoidClauseMethod · 0.95
selectMethod · 0.80
_findSeparateMethod · 0.80
getMethod · 0.65

Tested by 8

customFnFunction · 0.64
executeFunction · 0.64
testSuccessFunction · 0.64
testAsyncFunction · 0.64
updateFunction · 0.64
createUsersAndItemsFunction · 0.64
testFunction · 0.64