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

Commit 02975518 by Jan Aagaard Meier

Create an alias for connectorDAO for brevity

1 parent 650f533d
Showing with 13 additions and 12 deletions
...@@ -14,6 +14,7 @@ module.exports = (function() { ...@@ -14,6 +14,7 @@ module.exports = (function() {
var customEventEmitter = new Utils.CustomEventEmitter(function() { var customEventEmitter = new Utils.CustomEventEmitter(function() {
var where = {} var where = {}
, connectorDAO = self.__factory.connectorDAO
, options = _options || {} , options = _options || {}
, queryOptions = {} , queryOptions = {}
, association = self.__factory.target.associations[self.__factory.associationAccessor] , association = self.__factory.target.associations[self.__factory.associationAccessor]
...@@ -22,19 +23,19 @@ module.exports = (function() { ...@@ -22,19 +23,19 @@ module.exports = (function() {
var instancePrimaryKeys = Object.keys(self.instance.daoFactory.primaryKeys) var instancePrimaryKeys = Object.keys(self.instance.daoFactory.primaryKeys)
, instancePrimaryKey = instancePrimaryKeys.length > 0 ? instancePrimaryKeys[0] : 'id' , instancePrimaryKey = instancePrimaryKeys.length > 0 ? instancePrimaryKeys[0] : 'id'
where[self.__factory.connectorDAO.tableName+"."+self.__factory.identifier] = self.instance[instancePrimaryKey] where[connectorDAO.tableName+"."+self.__factory.identifier] = self.instance[instancePrimaryKey]
var primaryKeys = Object.keys(self.__factory.connectorDAO.primaryKeys) var primaryKeys = Object.keys(connectorDAO.primaryKeys)
, foreignKey = primaryKeys.filter(function(pk) { return pk != self.__factory.identifier })[0] , foreignKey = primaryKeys.filter(function(pk) { return pk != self.__factory.identifier })[0]
, foreignPrimary = Object.keys(self.__factory.target.primaryKeys) , foreignPrimary = Object.keys(self.__factory.target.primaryKeys)
foreignPrimary = foreignPrimary.length === 1 ? foreignPrimary[0] : 'id' foreignPrimary = foreignPrimary.length === 1 ? foreignPrimary[0] : 'id'
where[self.__factory.connectorDAO.tableName+"."+foreignKey] = {join: self.__factory.target.tableName+"."+foreignPrimary} where[connectorDAO.tableName+"."+foreignKey] = {join: self.__factory.target.tableName+"."+foreignPrimary}
if (association.customJoinTableModel) { if (association.customJoinTableModel) {
queryOptions.hasJoinTableModel = true queryOptions.hasJoinTableModel = true
queryOptions.joinTableModel = self.__factory.connectorDAO queryOptions.joinTableModel = connectorDAO
if (!options.attributes) { if (!options.attributes) {
options.attributes = [ options.attributes = [
...@@ -45,16 +46,16 @@ module.exports = (function() { ...@@ -45,16 +46,16 @@ module.exports = (function() {
if (options.joinTableAttributes) { if (options.joinTableAttributes) {
options.joinTableAttributes.forEach(function (elem) { options.joinTableAttributes.forEach(function (elem) {
options.attributes.push( options.attributes.push(
self.QueryInterface.quoteIdentifiers(self.__factory.connectorDAO.tableName + '.' + elem) + ' as ' + self.QueryInterface.quoteIdentifiers(connectorDAO.tableName + '.' + elem) + ' as ' +
self.QueryInterface.quoteIdentifier(self.__factory.connectorDAO.name + '.' + elem) self.QueryInterface.quoteIdentifier(connectorDAO.name + '.' + elem, true)
) )
}) })
} else { } else {
Utils._.forOwn(self.__factory.connectorDAO.rawAttributes, function (elem, key) { Utils._.forOwn(connectorDAO.rawAttributes, function (elem, key) {
options.attributes.push( options.attributes.push(
self.QueryInterface.quoteIdentifiers(self.__factory.connectorDAO.tableName + '.' + key) + ' as ' + self.QueryInterface.quoteIdentifiers(connectorDAO.tableName + '.' + key) + ' as ' +
self.QueryInterface.quoteIdentifier(self.__factory.connectorDAO.name + '.' + key) self.QueryInterface.quoteIdentifier(connectorDAO.name + '.' + key, true)
) )
}) })
} }
} }
...@@ -77,7 +78,7 @@ module.exports = (function() { ...@@ -77,7 +78,7 @@ module.exports = (function() {
options.where = where; options.where = where;
} }
self.__factory.target.findAllJoin(self.__factory.connectorDAO.tableName, options, queryOptions) self.__factory.target.findAllJoin(connectorDAO.tableName, options, queryOptions)
.on('success', function(objects) { customEventEmitter.emit('success', objects) }) .on('success', function(objects) { customEventEmitter.emit('success', objects) })
.on('error', function(err){ customEventEmitter.emit('error', err) }) .on('error', function(err){ customEventEmitter.emit('error', err) })
.on('sql', function(sql) { customEventEmitter.emit('sql', sql)}) .on('sql', function(sql) { customEventEmitter.emit('sql', sql)})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!