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

Commit 198f3501 by Joel Trost Committed by Matt Broadstone

Alias Test passes

1 parent 9f6c5f04
var common;
common.quoteTable: function(param, as) {
var table = '';
if (as === true) {
as = param.as || param.name || param;
}
if (_.isObject(param)) {
if (common._dialect.supports.schemas) {
if (param.schema) {
table += common.quoteIdentifier(param.schema) + '.';
}
table += common.quoteIdentifier(param.tableName);
} else {
if (param.schema) {
table += param.schema + param.delimiter;
}
table += param.tableName;
table = common.quoteIdentifier(table);
}
} else {
table = common.quoteIdentifier(param);
}
if (as) {
table += ' AS ' + common.quoteIdentifier(as);
}
return table;
};
/*
Escape an identifier (e.g. a table or attribute name)
*/
/* istanbul ignore next */
common.quoteIdentifier: function(identifier, force) {
throwMethodUndefined('quoteIdentifier');
},
/*
Split an identifier into .-separated tokens and quote each part
*/
common.quoteIdentifiers: function(identifiers, force) {
if (identifiers.indexOf('.') !== -1) {
identifiers = identifiers.split('.');
return common.quoteIdentifier(identifiers.slice(0, identifiers.length - 1).join('.')) + '.' + common.quoteIdentifier(identifiers[identifiers.length - 1]);
} else {
return common.quoteIdentifier(identifiers);
}
},
module.exports = function (queryGenerator) {
common = queryGenerator;
};
......@@ -23,6 +23,7 @@ module.exports = (function() {
Utils.inherit(Query, AbstractQuery);
Query.prototype.run = function(sql) {
console.log(sql);
var self = this;
this.sql = sql;
......
......@@ -459,16 +459,15 @@ module.exports = {
//we have joins
//add join table
query.push(loadFieldsWithName(model.rawAttributes, model.name));
if(options.include){
query.push(loadFieldsWithName(model.rawAttributes, model.name));
query.push(',');
for(var i = 0; i < options.include.length; i++){
if(options.include[i].as) {
query.push(joinFields(options.include[i].model.rawAttributes
, options.include[i].as));
}
}
}else {
query.push(loadFields(model.rawAttributes));
}
return query.join(' ');
},
......@@ -489,8 +488,18 @@ module.exports = {
break;
}
}
var associationType = include.association.associationType;
var rootKey = primaryKey;
var joinKey = quoteIdentifier(include.association.foreignKey);
if(associationType === 'BelongsTo'){
rootKey = quoteIdentifier(include.association.foreignKey);
joinKey = primaryKey;
}
var joinType = include.required ? 'INNER JOIN' : 'LEFT OUTER JOIN';
//var key, joinKey;
//console.log(include.association.associationType);
//if(include.association)
var joinTable = include.as ? include.as : include.model.name;
joinTable = quoteIdentifier(joinTable);
var tableName = quoteIdentifier(model.name);
......@@ -499,14 +508,19 @@ module.exports = {
joinType,
quoteIdentifier(include.model.tableName),
'AS', joinTable,
'ON', tableName + '.' + primaryKey,
'=', joinTable + '.' + quoteIdentifier(include.association.foreignKey)
'ON', tableName + '.' + rootKey,
'=', joinTable + '.' + joinKey
].join(' ');
},
getWhereClause: function(tableName, model, options){
//console.log('my model:', model);
}
};
getWhereClause: function(where, tableName){
var query = ['WHERE'];
for(var key in where){
query.push(quoteIdentifier(tableName) + '.' + quoteIdentifier(key));
query.push('=');
query.push(where[key]);
}
return query.join(' ');
}};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!