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

Method findAll

lib/model.js:1692–1781  ·  lib/model.js::Model.findAll

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

(options)

Source from the content-addressed store, hash-verified

1690 * @returns {Promise<Array<Model>>}
1691 */
1692 static async findAll(options) {
1693 if (options !== undefined && !_.isPlainObject(options)) {
1694 throw new sequelizeErrors.QueryError(class="st">'The argument passed to findAll must be an options object, use findByPk if you wish to pass a single primary key value');
1695 }
1696
1697 if (options !== undefined && options.attributes) {
1698 if (!Array.isArray(options.attributes) && !_.isPlainObject(options.attributes)) {
1699 throw new sequelizeErrors.QueryError(class="st">'The attributes option must be an array of column names or an object');
1700 }
1701 }
1702
1703 this.warnOnInvalidOptions(options, Object.keys(this.rawAttributes));
1704
1705 const tableNames = {};
1706
1707 tableNames[this.getTableName(options)] = true;
1708 options = Utils.cloneDeep(options);
1709
1710 _.defaults(options, { hooks: true });
1711
1712 class="cm">// set rejectOnEmpty option, defaults to model options
1713 options.rejectOnEmpty = Object.prototype.hasOwnProperty.call(options, class="st">'rejectOnEmpty')
1714 ? options.rejectOnEmpty
1715 : this.options.rejectOnEmpty;
1716
1717 this._injectScope(options);
1718
1719 if (options.hooks) {
1720 await this.runHooks(class="st">'beforeFind', options);
1721 }
1722 this._conformIncludes(options, this);
1723 this._expandAttributes(options);
1724 this._expandIncludeAll(options);
1725
1726 if (options.hooks) {
1727 await this.runHooks(class="st">'beforeFindAfterExpandIncludeAll', options);
1728 }
1729 options.originalAttributes = this._injectDependentVirtualAttributes(options.attributes);
1730
1731 if (options.include) {
1732 options.hasJoin = true;
1733
1734 this._validateIncludedElements(options, tableNames);
1735
1736 class="cm">// If we're not raw, we have to make sure we include the primary key for de-duplication
1737 if (
1738 options.attributes
1739 && !options.raw
1740 && this.primaryKeyAttribute
1741 && !options.attributes.includes(this.primaryKeyAttribute)
1742 && (!options.group || !options.hasSingleAssociation || options.hasMultiAssociation)
1743 ) {
1744 options.attributes = [this.primaryKeyAttribute].concat(options.attributes);
1745 }
1746 }
1747
1748 if (!options.attributes) {
1749 options.attributes = Object.keys(this.rawAttributes);

Callers 15

findOneMethod · 0.95
findAndCountAllMethod · 0.95
destroyMethod · 0.95
restoreMethod · 0.95
updateMethod · 0.95
include.tsFile · 0.80
where.tsFile · 0.80
testFunction · 0.80
attributes.tsFile · 0.80
sequelize.tsFile · 0.80
index-hints.tsFile · 0.80
trans2Function · 0.80

Calls 11

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

Tested by 7

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