不要怂,就是干,撸起袖子干!

Commit 589a90b1 by Jan Aagaard Meier

Renamed foreignKeyObject to foreignKeyAttribute

1 parent b11f57f3
...@@ -15,10 +15,10 @@ module.exports = (function() { ...@@ -15,10 +15,10 @@ module.exports = (function() {
this.as = this.options.as; this.as = this.options.as;
if (Utils._.isObject(this.options.foreignKey)) { if (Utils._.isObject(this.options.foreignKey)) {
this.foreignKeyObject = this.options.foreignKey; this.foreignKeyAttribute = this.options.foreignKey;
this.foreignKey = this.foreignKeyObject.fieldName; this.foreignKey = this.foreignKeyAttribute.fieldName;
} else { } else {
this.foreignKeyObject = {}; this.foreignKeyAttribute = {};
this.foreignKey = this.options.foreignKey; this.foreignKey = this.options.foreignKey;
} }
...@@ -54,7 +54,7 @@ module.exports = (function() { ...@@ -54,7 +54,7 @@ module.exports = (function() {
BelongsTo.prototype.injectAttributes = function() { BelongsTo.prototype.injectAttributes = function() {
var newAttributes = {}; var newAttributes = {};
newAttributes[this.identifier] = Utils._.defaults(this.foreignKeyObject, { type: this.options.keyType || this.target.rawAttributes[this.targetIdentifier].type }); newAttributes[this.identifier] = Utils._.defaults(this.foreignKeyAttribute, { type: this.options.keyType || this.target.rawAttributes[this.targetIdentifier].type });
if (this.options.constraints !== false) { if (this.options.constraints !== false) {
this.options.onDelete = this.options.onDelete || 'SET NULL'; this.options.onDelete = this.options.onDelete || 'SET NULL';
this.options.onUpdate = this.options.onUpdate || 'CASCADE'; this.options.onUpdate = this.options.onUpdate || 'CASCADE';
......
...@@ -29,10 +29,10 @@ module.exports = (function() { ...@@ -29,10 +29,10 @@ module.exports = (function() {
); );
if (Utils._.isObject(this.options.foreignKey)) { if (Utils._.isObject(this.options.foreignKey)) {
this.foreignKeyObject = this.options.foreignKey; this.foreignKeyAttribute = this.options.foreignKey;
this.foreignKey = this.foreignKeyObject.fieldName; this.foreignKey = this.foreignKeyAttribute.fieldName;
} else { } else {
this.foreignKeyObject = {}; this.foreignKeyAttribute = {};
this.foreignKey = this.options.foreignKey; this.foreignKey = this.options.foreignKey;
} }
...@@ -206,8 +206,8 @@ module.exports = (function() { ...@@ -206,8 +206,8 @@ module.exports = (function() {
// define a new model, which connects the models // define a new model, which connects the models
var sourceKeyType = this.source.rawAttributes[this.source.primaryKeyAttribute].type var sourceKeyType = this.source.rawAttributes[this.source.primaryKeyAttribute].type
, targetKeyType = this.target.rawAttributes[this.target.primaryKeyAttribute].type , targetKeyType = this.target.rawAttributes[this.target.primaryKeyAttribute].type
, sourceAttribute = Utils._.defaults(this.foreignKeyObject, { type: sourceKeyType }) , sourceAttribute = Utils._.defaults(this.foreignKeyAttribute, { type: sourceKeyType })
, targetAttribute = Utils._.defaults(this.targetAssociation.foreignKeyObject, { type: targetKeyType }); , targetAttribute = Utils._.defaults(this.targetAssociation.foreignKeyAttribute, { type: targetKeyType });
if (this.options.constraints !== false) { if (this.options.constraints !== false) {
sourceAttribute.references = this.source.getTableName(); sourceAttribute.references = this.source.getTableName();
...@@ -248,7 +248,7 @@ module.exports = (function() { ...@@ -248,7 +248,7 @@ module.exports = (function() {
} else { } else {
var newAttributes = {}; var newAttributes = {};
var constraintOptions = _.clone(this.options); // Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m var constraintOptions = _.clone(this.options); // Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m
newAttributes[this.identifier] = _.defaults(this.foreignKeyObject, { type: this.options.keyType || this.source.rawAttributes[this.source.primaryKeyAttribute].type }); newAttributes[this.identifier] = _.defaults(this.foreignKeyAttribute, { type: this.options.keyType || this.source.rawAttributes[this.source.primaryKeyAttribute].type });
if (this.options.constraints !== false) { if (this.options.constraints !== false) {
constraintOptions.onDelete = constraintOptions.onDelete || 'SET NULL'; constraintOptions.onDelete = constraintOptions.onDelete || 'SET NULL';
......
...@@ -15,10 +15,10 @@ module.exports = (function() { ...@@ -15,10 +15,10 @@ module.exports = (function() {
this.as = this.options.as; this.as = this.options.as;
if (Utils._.isObject(this.options.foreignKey)) { if (Utils._.isObject(this.options.foreignKey)) {
this.foreignKeyObject = this.options.foreignKey; this.foreignKeyAttribute = this.options.foreignKey;
this.foreignKey = this.foreignKeyObject.fieldName; this.foreignKey = this.foreignKeyAttribute.fieldName;
} else { } else {
this.foreignKeyObject = {}; this.foreignKeyAttribute = {};
this.foreignKey = this.options.foreignKey; this.foreignKey = this.options.foreignKey;
} }
...@@ -55,7 +55,7 @@ module.exports = (function() { ...@@ -55,7 +55,7 @@ module.exports = (function() {
var newAttributes = {} var newAttributes = {}
, keyType = this.source.rawAttributes[this.sourceIdentifier].type; , keyType = this.source.rawAttributes[this.sourceIdentifier].type;
newAttributes[this.identifier] = Utils._.defaults(this.foreignKeyObject, { type: this.options.keyType || keyType }); newAttributes[this.identifier] = Utils._.defaults(this.foreignKeyAttribute, { type: this.options.keyType || keyType });
Utils._.defaults(this.target.rawAttributes, newAttributes); Utils._.defaults(this.target.rawAttributes, newAttributes);
if (this.options.constraints !== false) { if (this.options.constraints !== false) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!