MCPcopy
hub / github.com/sequelize/sequelize / hasMany

Function hasMany

lib/associations/mixin.js:16–45  ·  view source on GitHub ↗
(target, options = {})

Source from the content-addressed store, hash-verified

14
15const Mixin = {
16 hasMany(target, options = {}) {
17 if (!isModel(target, this.sequelize)) {
18 throw new Error(`${this.name}.hasMany called with something that's not a subclass of Sequelize.Model`);
19 }
20
21 const source = this;
22
23 // Since this is a mixin, we'll need a unique letiable name for hooks (since Model will override our hooks option)
24 options.hooks = options.hooks === undefined ? false : Boolean(options.hooks);
25 options.useHooks = options.hooks;
26
27 Object.assign(options, _.omit(source.options, ['hooks']));
28
29 if (options.useHooks) {
30 this.runHooks('beforeAssociate', { source, target, type: HasMany }, options);
31 }
32
33 // the id is in the foreign table or in a connecting table
34 const association = new HasMany(source, target, options);
35 source.associations[association.associationAccessor] = association;
36
37 association._injectAttributes();
38 association.mixin(source.prototype);
39
40 if (options.useHooks) {
41 this.runHooks('afterAssociate', { source, target, type: HasMany, association }, options);
42 }
43
44 return association;
45 },
46
47 belongsToMany(target, options = {}) {
48 if (!isModel(target, this.sequelize)) {

Callers

nothing calls this directly

Calls 3

_injectAttributesMethod · 0.95
mixinMethod · 0.95
isModelFunction · 0.85

Tested by

no test coverage detected