()
| 112 | // the id is in the target table |
| 113 | // or in an extra table which connects two tables |
| 114 | _injectAttributes() { |
| 115 | const newAttributes = { |
| 116 | [this.foreignKey]: { |
| 117 | type: this.options.keyType || this.source.rawAttributes[this.sourceKeyAttribute].type, |
| 118 | allowNull: true, |
| 119 | ...this.foreignKeyAttribute |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | // Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m |
| 124 | const constraintOptions = { ...this.options }; |
| 125 | |
| 126 | if (this.options.constraints !== false) { |
| 127 | const target = this.target.rawAttributes[this.foreignKey] || newAttributes[this.foreignKey]; |
| 128 | constraintOptions.onDelete = constraintOptions.onDelete || (target.allowNull ? 'SET NULL' : 'CASCADE'); |
| 129 | constraintOptions.onUpdate = constraintOptions.onUpdate || 'CASCADE'; |
| 130 | } |
| 131 | |
| 132 | Helpers.addForeignKeyConstraints(newAttributes[this.foreignKey], this.source, this.target, constraintOptions, this.sourceKeyField); |
| 133 | Utils.mergeDefaults(this.target.rawAttributes, newAttributes); |
| 134 | |
| 135 | this.target.refreshAttributes(); |
| 136 | this.source.refreshAttributes(); |
| 137 | |
| 138 | this.identifierField = this.target.rawAttributes[this.foreignKey].field || this.foreignKey; |
| 139 | this.foreignKeyField = this.target.rawAttributes[this.foreignKey].field || this.foreignKey; |
| 140 | this.sourceKeyField = this.source.rawAttributes[this.sourceKey].field || this.sourceKey; |
| 141 | |
| 142 | Helpers.checkNamingCollision(this); |
| 143 | |
| 144 | return this; |
| 145 | } |
| 146 | |
| 147 | mixin(obj) { |
| 148 | const methods = ['get', 'count', 'hasSingle', 'hasAll', 'set', 'add', 'addMultiple', 'remove', 'removeMultiple', 'create']; |
no test coverage detected