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

Commit 696cc28e by Overlook Motel

Tidying code (no functional change)

1 parent 1fa99b9d
Showing with 17 additions and 20 deletions
......@@ -49,11 +49,14 @@ module.exports = (function() {
*/
this.associationAccessor = this.as
if (!this.associationAccessor && (typeof this.through === "string" || Object(this.through) === this.through)) {
this.associationAccessor = this.through.tableName || this.through
}
else if (!this.associationAccessor) {
this.associationAccessor = this.combinedTableName
if (!this.associationAccessor) {
if (typeof this.through === 'string') {
this.associationAccessor = this.through
} else if (Object(this.through) === this.through) {
this.associationAccessor = this.through.tableName
} else {
this.associationAccessor = this.combinedTableName
}
}
/*
......@@ -69,15 +72,15 @@ module.exports = (function() {
if (this.through) {
_.each(this.target.associations, function (association, accessor) {
if (self.source === association.target) {
var paired = false
var paired
// If through is default, we determine pairing by the accesor value (i.e. DAOFactory's using as won't pair, but regular ones will)
if (self.through === true && accessor === self.associationAccessor) {
paired = true
if (self.through === true) {
paired = accessor === self.associationAccessor
}
// If through is not default, determine pairing by through value (model/string)
if (self.through !== true && self.options.through === association.options.through) {
paired = true
else {
paired = self.options.through === association.options.through
}
// If paired, set properties identifying both associations as double linked, and allow them to each eachtoerh
if (paired) {
......@@ -90,13 +93,12 @@ module.exports = (function() {
}
})
}
/*
* If we are double linked, and through is either default or a string, we create the through model and set it on both associations
*/
if (this.doubleLinked) {
if (this.through === true) {
this.through = this.combinedTableName
}
if (this.doubleLinked && this.through === true) {
this.through = this.combinedTableName
}
if (typeof this.through === "string") {
......@@ -185,8 +187,7 @@ module.exports = (function() {
})
// define a new model, which connects the models
var combinedTableAttributes = {}
, 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
, sourceAttribute = { type: sourceKeyType }
, targetAttribute = { type: targetKeyType }
......@@ -206,15 +207,11 @@ module.exports = (function() {
if (primaryKeyDeleted) {
targetAttribute.primaryKey = sourceAttribute.primaryKey = true
} else {
var uniqueKey = [this.through.tableName, this.identifier, this.foreignIdentifier, 'unique'].join('_')
targetAttribute.unique = sourceAttribute.unique = uniqueKey
}
combinedTableAttributes[this.identifier] = sourceAttribute
combinedTableAttributes[this.foreignIdentifier] = targetAttribute
if (!this.through.rawAttributes[this.identifier]) {
this.through.rawAttributes[this.identifier] = {
_autoGenerated: true
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!