* 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)
| 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); |