node-ejs-renderer/node_modules/sequelize/lib/associations/has-one.js.map

8 lines
13 KiB
Plaintext
Raw Normal View History

2024-06-09 13:55:01 -04:00
{
"version": 3,
"sources": ["../../src/associations/has-one.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-one association\n *\n * In the API reference below, add the name of the association to the method, e.g. for `User.hasOne(Project)` the getter will be `user.getProject()`.\n * This is almost the same as `belongsTo` with one exception - The foreign key will be defined on the target model.\n *\n * @see {@link Model.hasOne}\n */\nclass HasOne extends Association {\n constructor(source, target, options) {\n super(source, target, options);\n\n this.associationType = 'HasOne';\n this.isSingleAssociation = true;\n this.foreignKeyAttribute = {};\n\n if (this.as) {\n this.isAliased = true;\n this.options.name = {\n singular: this.as\n };\n } else {\n this.as = this.target.options.name.singular;\n this.options.name = this.target.options.name;\n }\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 Utils.singularize(this.options.as || this.source.name),\n this.source.primaryKeyAttribute\n ].join('_')\n );\n }\n\n if (\n this.options.sourceKey\n && !this.source.rawAttributes[this.options.sourceKey]\n ) {\n throw new Error(`Unknown attribute \"${this.options.sourceKey}\" passed as sourceKey, define this attribute on model \"${this.source.name}\" first`);\n }\n\n this.sourceKey = this.sourceKeyAttribute = this.options.sourceKey || this.source.primaryKeyAttribute;\n this.sourceKeyField = this.source.rawAttributes[this.sourceKey].field || this.sourceKey;\n this.sourceKeyIsPrimary = this.sourceKey === this.source.primaryKeyAttribute;\n\n this.associationAccessor = this.as;\n this.options.useHooks = options.useHooks;\n\n if (this.target.rawAttributes[this.foreignKey]) {\n this.identifierField = this.target.rawAttributes[this.foreignKey].field || this.foreignKey;\n }\n\n // Get singular name, trying to uppercase the first letter, unless the model forbids it\n const singular = _.upperFirst(this.options.name.singular);\n\n this.accessors = {\n get: `get${singular}`,\n set: `set${singular}`,\n create: `create${singular}`\n };\n }\n\n // the id is in the target table\n _injectAttributes() {\n const newAttributes = {\n [this.foreignKey]: {\n type: this.options.keyType || this.source.rawAttributes[this.sourceKey].type,\n allowNull: true,\n ...this.foreignKeyAttribute\n }\n };\n\n if (this.options.constraints !== false) {\n const target = this.target.rawAttributes[this.foreignKey] || newAttributes[this.foreignKey];\n this.options.onDelete = this.options.onDelete || (target.allowNull ? 'SET NULL' : 'CASCADE');\n this.options.onUpdate = this.options.onUpdate || 'CASCADE';\n }\n\n Helpers.addForeignKeyConstraints(newAttributes[this.foreignKey], this.source, this.target, this.options, this.sourceKeyField);\n Utils.mergeDefaults(this.target.rawAttributes, newAttributes);\n\n this.target.refreshAttributes();\n\n this.identifierField = this.target.rawAttributes[this.foreignKey].field || this.foreignKey;\n\n Helpers.checkNamingCollision(this);\n\n return this;\n }\n\n mixin(obj) {\n const methods = ['get', 'set', 'create'];\n\n Helpers.mixinMethods(this, obj, methods);\n }\n\n /**\n * Get the associated instance.\n *\n * @param {Model|Array<Model>} instances source instances\n * @param {object} [options] find options\n * @param {string|boolean} [options.scope] Apply a scope on the related model, or remove its default scope
"mappings": ";;;;;;;;;;;;;;;;;;;;AAEA,MAAM,QAAQ,QAAQ;AACtB,MAAM,UAAU,QAAQ;AACxB,MAAM,IAAI,QAAQ;AAClB,MAAM,cAAc,QAAQ;AAC5B,MAAM,KAAK,QAAQ;AAUnB,qBAAqB,YAAY;AAAA,EAC/B,YAAY,QAAQ,QAAQ,SAAS;AACnC,UAAM,QAAQ,QAAQ;AAEtB,SAAK,kBAAkB;AACvB,SAAK,sBAAsB;AAC3B,SAAK,sBAAsB;AAE3B,QAAI,KAAK,IAAI;AACX,WAAK,YAAY;AACjB,WAAK,QAAQ,OAAO;AAA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