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

Commit fc27da44 by Jan Aagaard Meier

slight variable renaming

1 parent 02975518
...@@ -33,7 +33,7 @@ module.exports = (function() { ...@@ -33,7 +33,7 @@ module.exports = (function() {
where[connectorDAO.tableName+"."+foreignKey] = {join: self.__factory.target.tableName+"."+foreignPrimary} where[connectorDAO.tableName+"."+foreignKey] = {join: self.__factory.target.tableName+"."+foreignPrimary}
if (association.customJoinTableModel) { if (association.hasJoinTableModel) {
queryOptions.hasJoinTableModel = true queryOptions.hasJoinTableModel = true
queryOptions.joinTableModel = connectorDAO queryOptions.joinTableModel = connectorDAO
...@@ -111,7 +111,7 @@ module.exports = (function() { ...@@ -111,7 +111,7 @@ module.exports = (function() {
if (!newObj) { if (!newObj) {
obsoleteAssociations.push(old) obsoleteAssociations.push(old)
} else if (association.customJoinTableModel) { } else if (association.hasJoinTableModel) {
var changedAssociation = { var changedAssociation = {
where: {}, where: {},
attributes: Utils._.defaults({}, newObj[self.__factory.connectorDAO.name], defaultAttributes) attributes: Utils._.defaults({}, newObj[self.__factory.connectorDAO.name], defaultAttributes)
...@@ -142,14 +142,10 @@ module.exports = (function() { ...@@ -142,14 +142,10 @@ module.exports = (function() {
attributes[self.__factory.identifier] = ((sourceKeys.length === 1) ? self.instance[sourceKeys[0]] : self.instance.id) attributes[self.__factory.identifier] = ((sourceKeys.length === 1) ? self.instance[sourceKeys[0]] : self.instance.id)
attributes[foreignIdentifier] = ((targetKeys.length === 1) ? unassociatedObject[targetKeys[0]] : unassociatedObject.id) attributes[foreignIdentifier] = ((targetKeys.length === 1) ? unassociatedObject[targetKeys[0]] : unassociatedObject.id)
if (association.customJoinTableModel) { if (association.hasJoinTableModel) {
attributes = Utils._.defaults(attributes, unassociatedObject[association.connectorDAO.name], defaultAttributes) attributes = Utils._.defaults(attributes, unassociatedObject[association.connectorDAO.name], defaultAttributes)
} }
if (association.customJoinTableModel) {
attributes = Utils._.defaults(attributes, unassociatedObject[association.connectorDAO.name], defaultAttributes)
}
return attributes return attributes
}) })
...@@ -180,13 +176,13 @@ module.exports = (function() { ...@@ -180,13 +176,13 @@ module.exports = (function() {
attributes[this.__factory.identifier] = ((sourceKeys.length === 1) ? this.instance[sourceKeys[0]] : this.instance.id) attributes[this.__factory.identifier] = ((sourceKeys.length === 1) ? this.instance[sourceKeys[0]] : this.instance.id)
attributes[foreignIdentifier] = ((targetKeys.length === 1) ? newAssociation[targetKeys[0]] : newAssociation.id) attributes[foreignIdentifier] = ((targetKeys.length === 1) ? newAssociation[targetKeys[0]] : newAssociation.id)
if (exists) { // implies customJoinTableModel === true if (exists) { // implies hasJoinTableModel === true
var where = attributes var where = attributes
attributes = Utils._.defaults({}, newAssociation[association.connectorDAO.name], additionalAttributes) attributes = Utils._.defaults({}, newAssociation[association.connectorDAO.name], additionalAttributes)
association.connectorDAO.update(attributes, where).proxy(emitterProxy) association.connectorDAO.update(attributes, where).proxy(emitterProxy)
} else { } else {
if (association.customJoinTableModel === true) { if (association.hasJoinTableModel === true) {
attributes = Utils._.defaults(attributes, newAssociation[association.connectorDAO.name], additionalAttributes) attributes = Utils._.defaults(attributes, newAssociation[association.connectorDAO.name], additionalAttributes)
} }
......
...@@ -13,10 +13,10 @@ module.exports = (function() { ...@@ -13,10 +13,10 @@ module.exports = (function() {
this.options = options this.options = options
this.useJunctionTable = this.options.useJunctionTable === undefined ? true : this.options.useJunctionTable this.useJunctionTable = this.options.useJunctionTable === undefined ? true : this.options.useJunctionTable
this.isSelfAssociation = (this.source.tableName === this.target.tableName) this.isSelfAssociation = (this.source.tableName === this.target.tableName)
this.customJoinTableModel = !!this.options.joinTableModel this.hasJoinTableModel = !!this.options.joinTableModel
var combinedTableName; var combinedTableName;
if (this.customJoinTableModel) { if (this.hasJoinTableModel) {
combinedTableName = this.options.joinTableModel.tableName combinedTableName = this.options.joinTableModel.tableName
} else if (this.options.joinTableName) { } else if (this.options.joinTableName) {
combinedTableName = this.options.joinTableName combinedTableName = this.options.joinTableName
...@@ -68,7 +68,7 @@ module.exports = (function() { ...@@ -68,7 +68,7 @@ module.exports = (function() {
combinedTableAttributes[this.identifier] = {type: sourceKeyType, primaryKey: true} combinedTableAttributes[this.identifier] = {type: sourceKeyType, primaryKey: true}
combinedTableAttributes[this.foreignIdentifier] = {type: targetKeyType, primaryKey: true} combinedTableAttributes[this.foreignIdentifier] = {type: targetKeyType, primaryKey: true}
if (this.customJoinTableModel === true) { if (this.hasJoinTableModel === true) {
this.connectorDAO = this.options.joinTableModel this.connectorDAO = this.options.joinTableModel
this.connectorDAO.rawAttributes = Utils._.merge(this.connectorDAO.rawAttributes, combinedTableAttributes) this.connectorDAO.rawAttributes = Utils._.merge(this.connectorDAO.rawAttributes, combinedTableAttributes)
...@@ -187,7 +187,7 @@ module.exports = (function() { ...@@ -187,7 +187,7 @@ module.exports = (function() {
instance[self.accessors.get]({ where: where }) instance[self.accessors.get]({ where: where })
.error(function(err){ emitter.emit('error', err)}) .error(function(err){ emitter.emit('error', err)})
.success(function(currentAssociatedObjects) { .success(function(currentAssociatedObjects) {
if (currentAssociatedObjects.length === 0 || self.customJoinTableModel === true) { if (currentAssociatedObjects.length === 0 || self.hasJoinTableModel === true) {
var Class = self.connectorDAO ? HasManyMultiLinked : HasManySingleLinked var Class = self.connectorDAO ? HasManyMultiLinked : HasManySingleLinked
new Class(self, instance).injectAdder(emitter, newAssociatedObject, additionalAttributes, !!currentAssociatedObjects.length) new Class(self, instance).injectAdder(emitter, newAssociatedObject, additionalAttributes, !!currentAssociatedObjects.length)
} else { } else {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!