MCPcopy
hub / github.com/sequelize/sequelize / count

Method count

lib/associations/belongs-to-many.js:494–508  ·  view source on GitHub ↗

* Count everything currently associated with this, using an optional where clause. * * @param {Model} instance instance * @param {object} [options] find options * @param {object} [options.where] An optional where clause to limit the associated models * @param {string|boolean} [options

(instance, options)

Source from the content-addressed store, hash-verified

492 * @returns {Promise<number>}
493 */
494 async count(instance, options) {
495 const sequelize = this.target.sequelize;
496
497 options = Utils.cloneDeep(options);
498 options.attributes = [
499 [sequelize.fn('COUNT', sequelize.col([this.target.name, this.targetKeyField].join('.'))), 'count']
500 ];
501 options.joinTableAttributes = [];
502 options.raw = true;
503 options.plain = true;
504
505 const result = await this.get(instance, options);
506
507 return parseInt(result.count, 10);
508 }
509
510 /**
511 * Check if one or more instance(s) are associated with this. If a list of instances is passed, the function returns true if _all_ instances are associated

Callers

nothing calls this directly

Calls 3

getMethod · 0.95
colMethod · 0.80
fnMethod · 0.45

Tested by

no test coverage detected