MCPcopy
hub / github.com/sequelize/sequelize / has

Method has

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

* Check if one or more rows are associated with `this`. * * @param {Model} sourceInstance the source instance * @param {Model|Model[]|string[]|string|number[]|number} [targetInstances] Can be an array of instances or their primary keys * @param {object} [options] Options passed to getAss

(sourceInstance, targetInstances, options)

Source from the content-addressed store, hash-verified

280 * @returns {Promise}
281 */
282 async has(sourceInstance, targetInstances, options) {
283 const where = {};
284
285 if (!Array.isArray(targetInstances)) {
286 targetInstances = [targetInstances];
287 }
288
289 options = {
290 ...options,
291 scope: false,
292 attributes: [this.target.primaryKeyAttribute],
293 raw: true
294 };
295
296 where[Op.or] = targetInstances.map(instance => {
297 if (instance instanceof this.target) {
298 return instance.where();
299 }
300 return {
301 [this.target.primaryKeyAttribute]: instance
302 };
303 });
304
305 options.where = {
306 [Op.and]: [
307 where,
308 options.where
309 ]
310 };
311
312 const associatedObjects = await this.get(sourceInstance, options);
313
314 return associatedObjects.length === targetInstances.length;
315 }
316
317 /**
318 * Set the associated models by passing an array of persisted instances or their primary keys. Everything that is not in the passed array will be un-associated

Callers 14

refreshAttributesMethod · 0.45
warnOnInvalidOptionsMethod · 0.45
setMethod · 0.45
changedMethod · 0.45
saveMethod · 0.45
mapFinderOptionsFunction · 0.45
mapValueFieldNamesFunction · 0.45
nowFunction · 0.45
getOperatorsFunction · 0.45
parserStore.jsFile · 0.45
attributeToSQLMethod · 0.45

Calls 2

getMethod · 0.95
whereMethod · 0.45

Tested by

no test coverage detected