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

Commit a07016ec by Lemon

Non-'id' primary key include support - SQLite

1 parent e5228e7e
...@@ -192,7 +192,7 @@ module.exports = (function() { ...@@ -192,7 +192,7 @@ module.exports = (function() {
var as = include.as var as = include.as
if (!include.association.connectorDAO) { if (!include.association.connectorDAO) {
var primaryKeysLeft = ((include.association.associationType === 'BelongsTo') ? Object.keys(include.association.target.primaryKeys) : Object.keys(include.association.source.primaryKeys)); var primaryKeysLeft = ((include.association.associationType === 'BelongsTo') ? Object.keys(include.association.target.primaryKeys) : Object.keys(include.association.source.primaryKeys))
var tableLeft = ((include.association.associationType === 'BelongsTo') ? include.as : tableName) var tableLeft = ((include.association.associationType === 'BelongsTo') ? include.as : tableName)
var attrLeft = ((primaryKeysLeft.length !== 1) ? 'id' : primaryKeysLeft[0]) var attrLeft = ((primaryKeysLeft.length !== 1) ? 'id' : primaryKeysLeft[0])
var tableRight = ((include.association.associationType === 'BelongsTo') ? tableName : include.as) var tableRight = ((include.association.associationType === 'BelongsTo') ? tableName : include.as)
......
...@@ -170,26 +170,30 @@ module.exports = (function() { ...@@ -170,26 +170,30 @@ module.exports = (function() {
optAttributes = optAttributes.concat(attributes) optAttributes = optAttributes.concat(attributes)
var table = include.daoFactory.tableName
var as = include.as
if (!include.association.connectorDAO) { if (!include.association.connectorDAO) {
var table = include.daoFactory.tableName var primaryKeysLeft = ((include.association.associationType === 'BelongsTo') ? Object.keys(include.association.target.primaryKeys) : Object.keys(include.association.source.primaryKeys))
var as = include.as
var tableLeft = ((include.association.associationType === 'BelongsTo') ? include.as : tableName) var tableLeft = ((include.association.associationType === 'BelongsTo') ? include.as : tableName)
var attrLeft = 'id' var attrLeft = ((primaryKeysLeft.length !== 1) ? 'id' : primaryKeysLeft[0])
var tableRight = ((include.association.associationType === 'BelongsTo') ? tableName : include.as) var tableRight = ((include.association.associationType === 'BelongsTo') ? tableName : include.as)
var attrRight = include.association.identifier var attrRight = include.association.identifier
joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(table) + " AS " + this.quoteIdentifier(as) + " ON " + this.quoteIdentifier(tableLeft) + "." + this.quoteIdentifier(attrLeft) + " = " + this.quoteIdentifier(tableRight) + "." + this.quoteIdentifier(attrRight) joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(table) + " AS " + this.quoteIdentifier(as) + " ON " + this.quoteIdentifier(tableLeft) + "." + this.quoteIdentifier(attrLeft) + " = " + this.quoteIdentifier(tableRight) + "." + this.quoteIdentifier(attrRight)
} else { } else {
var table = include.daoFactory.tableName var primaryKeysSource = Object.keys(include.association.source.primaryKeys);
var as = include.as var tableSource = tableName
var tableLeft = tableName var identSource = include.association.identifier
var identLeft = include.association.identifier var attrSource = ((!include.association.source.hasPrimaryKeys || primaryKeysSource.length !== 1) ? 'id' : primaryKeysSource[0])
var attrLeft = 'id'
var tableRight = include.as var primaryKeysTarget = Object.keys(include.association.target.primaryKeys);
var identRight = include.association.foreignIdentifier var tableTarget = include.as
var attrRight = 'id' var identTarget = include.association.foreignIdentifier
var attrTarget = ((!include.association.target.hasPrimaryKeys || primaryKeysTarget.length !== 1) ? 'id' : primaryKeysTarget[0])
var tableJunction = include.association.connectorDAO.tableName var tableJunction = include.association.connectorDAO.tableName
joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(tableJunction) + " ON " + this.quoteIdentifier(tableLeft) + "." + this.quoteIdentifier(attrLeft) + " = " + this.quoteIdentifier(tableJunction) + "." + this.quoteIdentifier(identLeft) joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(tableJunction) + " ON " + this.quoteIdentifier(tableSource) + "." + this.quoteIdentifier(attrSource) + " = " + this.quoteIdentifier(tableJunction) + "." + this.quoteIdentifier(identSource)
joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(table) + " AS " + this.quoteIdentifier(as) + " ON " + this.quoteIdentifier(tableRight) + "." + this.quoteIdentifier(attrRight) + " = " + this.quoteIdentifier(tableJunction) + "." + this.quoteIdentifier(identRight) joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(table) + " AS " + this.quoteIdentifier(as) + " ON " + this.quoteIdentifier(tableTarget) + "." + this.quoteIdentifier(attrTarget) + " = " + this.quoteIdentifier(tableJunction) + "." + this.quoteIdentifier(identTarget)
} }
}.bind(this)) }.bind(this))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!