API/api.medcify.app/node_modules/sequelize/lib/associations/belongs-to-many.js.map

8 lines
42 KiB
Plaintext
Raw Permalink Normal View History

2022-09-26 06:11:44 +00:00
{
"version": 3,
"sources": ["../../src/associations/belongs-to-many.js"],
"sourcesContent": ["'use strict';\n\nconst Utils = require('./../utils');\nconst Helpers = require('./helpers');\nconst _ = require('lodash');\nconst Association = require('./base');\nconst BelongsTo = require('./belongs-to');\nconst HasMany = require('./has-many');\nconst HasOne = require('./has-one');\nconst AssociationError = require('../errors').AssociationError;\nconst EmptyResultError = require('../errors').EmptyResultError;\nconst Op = require('../operators');\n\n/**\n * Many-to-many association with a join table.\n *\n * When the join table has additional attributes, these can be passed in the options object:\n *\n * ```js\n * UserProject = sequelize.define('user_project', {\n * role: Sequelize.STRING\n * });\n * User.belongsToMany(Project, { through: UserProject });\n * Project.belongsToMany(User, { through: UserProject });\n * // through is required!\n *\n * user.addProject(project, { through: { role: 'manager' }});\n * ```\n *\n * All methods allow you to pass either a persisted instance, its primary key, or a mixture:\n *\n * ```js\n * const project = await Project.create({ id: 11 });\n * await user.addProjects([project, 12]);\n * ```\n *\n * If you want to set several target instances, but with different attributes you have to set the attributes on the instance, using a property with the name of the through model:\n *\n * ```js\n * p1.UserProjects = {\n * started: true\n * }\n * user.setProjects([p1, p2], { through: { started: false }}) // The default value is false, but p1 overrides that.\n * ```\n *\n * Similarly, when fetching through a join table with custom attributes, these attributes will be available as an object with the name of the through model.\n * ```js\n * const projects = await user.getProjects();\n * const p1 = projects[0];\n * p1.UserProjects.started // Is this project started yet?\n * ```\n *\n * In the API reference below, add the name of the association to the method, e.g. for `User.belongsToMany(Project)` the getter will be `user.getProjects()`.\n *\n * @see {@link Model.belongsToMany}\n */\nclass BelongsToMany extends Association {\n constructor(source, target, options) {\n super(source, target, options);\n\n if (this.options.through === undefined || this.options.through === true || this.options.through === null) {\n throw new AssociationError(`${source.name}.belongsToMany(${target.name}) requires through option, pass either a string or a model`);\n }\n\n if (!this.options.through.model) {\n this.options.through = {\n model: options.through\n };\n }\n\n this.associationType = 'BelongsToMany';\n this.targetAssociation = null;\n this.sequelize = source.sequelize;\n this.through = { ...this.options.through };\n this.isMultiAssociation = true;\n this.doubleLinked = false;\n\n if (!this.as && this.isSelfAssociation) {\n throw new AssociationError('\\'as\\' must be defined for many-to-many self-associations');\n }\n\n if (this.as) {\n this.isAliased = true;\n\n if (_.isPlainObject(this.as)) {\n this.options.name = this.as;\n this.as = this.as.plural;\n } else {\n this.options.name = {\n plural: this.as,\n singular: Utils.singularize(this.as)\n };\n }\n } else {\n this.as = this.target.options.name.plural;\n this.options.name = this.target.options.name;\n }\n\n this.combinedTableName = Utils.combineTableNames(\n this.source.tableName,\n this.isSelfAssociation ? this.as || this.target.tableName : this.target.tableName\n );\n\n /*\n * If self association, this is the target association - Unless we find a pairing association\n */\n if (this.isSelfAssociation) {\n this.targetAssociation = this;\n }\n\n /*\n * Find paired association (if exists)\n */\n _.each(this.target.associations, association => {\n if (association.associationType !== 'BelongsToMany') return;\n if (association.target !== this.source) return;\n\n if (this.options.through.model === association.options.through.mo
"mappings": ";;;;;;;;;;;;;;;;;;;;AAEA,MAAM,QAAQ,QAAQ;AACtB,MAAM,UAAU,QAAQ;AACxB,MAAM,IAAI,QAAQ;AAClB,MAAM,cAAc,QAAQ;AAC5B,MAAM,YAAY,QAAQ;AAC1B,MAAM,UAAU,QAAQ;AACxB,MAAM,SAAS,QAAQ;AACvB,MAAM,mBAAmB,QAAQ,aAAa;AAC9C,MAAM,mBAAmB,QAAQ,aAAa;AAC9C,MAAM,KAAK,QAAQ;AA6CnB,4BAA4B,YAAY;AAAA,EACtC,YAAY,QAAQ,QAAQ,SAAS;AACnC,UAAM,QAAQ,QAAQ;AAEtB,QAAI,KAAK,QAAQ,YAAY,UAAa,KAAK,QAAQ,YAAY,QAAQ,KAAK,QAAQ,YAAY,MAAM;AACxG,YAAM,IAAI,iBAAiB,GAAG,OAAO,sBAAsB,OAAO;AAAA;AAGpE,QAAI,CAAC,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