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

Method count

lib/associations/has-many.js:253–271  ·  view source on GitHub ↗

* Count everything currently associated with this, using an optional where clause. * * @param {Model} instance the source instance * @param {object} [options] find & count options * @param {object} [options.where] An optional where clause to limit the associated mo

(instance, options)

Source from the content-addressed store, hash-verified

251 * @returns {Promise<number>}
252 */
253 async count(instance, options) {
254 options = Utils.cloneDeep(options);
255
256 options.attributes = [
257 [
258 this.sequelize.fn(
259 'COUNT',
260 this.sequelize.col(`${this.target.name}.${this.target.primaryKeyField}`)
261 ),
262 'count'
263 ]
264 ];
265 options.raw = true;
266 options.plain = true;
267
268 const result = await this.get(instance, options);
269
270 return parseInt(result.count, 10);
271 }
272
273 /**
274 * Check if one or more rows are associated with `this`.

Callers

nothing calls this directly

Calls 3

getMethod · 0.95
colMethod · 0.80
fnMethod · 0.45

Tested by

no test coverage detected