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

Commit 04c3feb1 by Mick Hansen

do foreignKey check on paired after model has been defined for through: string on BTM

1 parent ca2714e7
Showing with 11 additions and 11 deletions
...@@ -146,17 +146,6 @@ module.exports = (function() { ...@@ -146,17 +146,6 @@ module.exports = (function() {
} }
}, this); }, this);
if (this.paired) {
if (this.otherKeyDefault) {
this.otherKey = this.paired.foreignKey;
}
if (this.paired.otherKeyDefault) {
// If paired otherKey was inferred we should make sure to clean it up before adding a new one that matches the foreignKey
delete this.through.model.rawAttributes[this.paired.otherKey];
this.paired.otherKey = this.foreignKey;
}
}
if (typeof this.through.model === 'string') { if (typeof this.through.model === 'string') {
if (!this.sequelize.isDefined(this.through.model)) { if (!this.sequelize.isDefined(this.through.model)) {
this.through.model = this.sequelize.define(this.through.model, {}, _.extend(this.options, { this.through.model = this.sequelize.define(this.through.model, {}, _.extend(this.options, {
...@@ -173,6 +162,17 @@ module.exports = (function() { ...@@ -173,6 +162,17 @@ module.exports = (function() {
this.throughModel = this.through.model; this.throughModel = this.through.model;
} }
if (this.paired) {
if (this.otherKeyDefault) {
this.otherKey = this.paired.foreignKey;
}
if (this.paired.otherKeyDefault) {
// If paired otherKey was inferred we should make sure to clean it up before adding a new one that matches the foreignKey
delete this.through.model.rawAttributes[this.paired.otherKey];
this.paired.otherKey = this.foreignKey;
}
}
this.options.tableName = this.combinedName = (this.through.model === Object(this.through.model) ? this.through.model.tableName : this.through.model); this.options.tableName = this.combinedName = (this.through.model === Object(this.through.model) ? this.through.model.tableName : this.through.model);
if (this.as) { if (this.as) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!