8 lines
22 KiB
Plaintext
8 lines
22 KiB
Plaintext
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../../src/associations/has-many.js"],
|
||
|
"sourcesContent": ["'use strict';\n\nconst Utils = require('./../utils');\nconst Helpers = require('./helpers');\nconst _ = require('lodash');\nconst Association = require('./base');\nconst Op = require('../operators');\n\n/**\n * One-to-many association\n *\n * In the API reference below, add the name of the association to the method, e.g. for `User.hasMany(Project)` the getter will be `user.getProjects()`.\n * If the association is aliased, use the alias instead, e.g. `User.hasMany(Project, { as: 'jobs' })` will be `user.getJobs()`.\n *\n * @see {@link Model.hasMany}\n */\nclass HasMany extends Association {\n constructor(source, target, options) {\n super(source, target, options);\n\n this.associationType = 'HasMany';\n this.targetAssociation = null;\n this.sequelize = source.sequelize;\n this.isMultiAssociation = true;\n this.foreignKeyAttribute = {};\n\n if (this.options.through) {\n throw new Error('N:M associations are not supported with hasMany. Use belongsToMany instead');\n }\n\n /*\n * If self association, this is the target association\n */\n if (this.isSelfAssociation) {\n this.targetAssociation = this;\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 /*\n * Foreign key setup\n */\n if (_.isObject(this.options.foreignKey)) {\n this.foreignKeyAttribute = this.options.foreignKey;\n this.foreignKey = this.foreignKeyAttribute.name || this.foreignKeyAttribute.fieldName;\n } else if (this.options.foreignKey) {\n this.foreignKey = this.options.foreignKey;\n }\n\n if (!this.foreignKey) {\n this.foreignKey = Utils.camelize(\n [\n this.source.options.name.singular,\n this.source.primaryKeyAttribute\n ].join('_')\n );\n }\n\n if (this.target.rawAttributes[this.foreignKey]) {\n this.identifierField = this.target.rawAttributes[this.foreignKey].field || this.foreignKey;\n this.foreignKeyField = this.target.rawAttributes[this.foreignKey].field || this.foreignKey;\n }\n\n /*\n * Source key setup\n */\n this.sourceKey = this.options.sourceKey || this.source.primaryKeyAttribute;\n\n if (this.source.rawAttributes[this.sourceKey]) {\n this.sourceKeyAttribute = this.sourceKey;\n this.sourceKeyField = this.source.rawAttributes[this.sourceKey].field || this.sourceKey;\n } else {\n this.sourceKeyAttribute = this.source.primaryKeyAttribute;\n this.sourceKeyField = this.source.primaryKeyField;\n }\n\n // Get singular and plural names\n // try to uppercase the first letter, unless the model forbids it\n const plural = _.upperFirst(this.options.name.plural);\n const singular = _.upperFirst(this.options.name.singular);\n\n this.associationAccessor = this.as;\n this.accessors = {\n get: `get${plural}`,\n set: `set${plural}`,\n addMultiple: `add${plural}`,\n add: `add${singular}`,\n create: `create${singular}`,\n remove: `remove${singular}`,\n removeMultiple: `remove${plural}`,\n hasSingle: `has${singular}`,\n hasAll: `has${plural}`,\n count: `count${plural}`\n };\n }\n\n // the id is in the target table\n // or in an extra table which connects two tables\n _injectAttributes() {\n const newAttributes = {\n [this.foreignKey]: {\n type: this.options.keyType || this.source.rawAttributes[this.sourceKeyAttribute].type,\n allowNull: true,\n ...this.foreignKeyAttribute\n }\n };\n\n // Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m\n const constraintOptions = { ...this
|
||
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAEA,MAAM,QAAQ,QAAQ;AACtB,MAAM,UAAU,QAAQ;AACxB,MAAM,IAAI,QAAQ;AAClB,MAAM,cAAc,QAAQ;AAC5B,MAAM,KAAK,QAAQ;AAUnB,sBAAsB,YAAY;AAAA,EAChC,YAAY,QAAQ,QAAQ,SAAS;AACnC,UAAM,QAAQ,QAAQ;AAEtB,SAAK,kBAAkB;AACvB,SAAK,oBAAoB;AACzB,SAAK,YAAY,OAAO;AACxB,SAAK,qBAAqB;AAC1B,SAAK,sBAAsB;AAE3B,QAAI,KAAK,QAAQ,SAAS;AACxB,YAAM,IAAI,MAAM;AAAA;AAMlB,QAAI,KAAK,mBA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