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

Commit 79b80a8e by Joel Trost Committed by Matt Broadstone

Fixed bug in lib/model.js deleting clauses

1 parent da053191
...@@ -780,7 +780,6 @@ module.exports = (function() { ...@@ -780,7 +780,6 @@ module.exports = (function() {
selectQuery: function(tableName, options, model) { selectQuery: function(tableName, options, model) {
// Enter and change at your own peril -- Mick Hansen // Enter and change at your own peril -- Mick Hansen
options = options || {}; options = options || {};
var table = null var table = null
...@@ -1259,7 +1258,7 @@ module.exports = (function() { ...@@ -1259,7 +1258,7 @@ module.exports = (function() {
} }
query += ';'; query += ';';
console.log(query); //console.log(query);
return query; return query;
}, },
......
...@@ -383,6 +383,7 @@ module.exports = (function() { ...@@ -383,6 +383,7 @@ module.exports = (function() {
//console.log('tablename', tableName); //console.log('tablename', tableName);
//console.log('options', options); //console.log('options', options);
//console.log('model', model); //console.log('model', model);
//console.log(options.where);
options = options || {}; options = options || {};
var query = [ var query = [
...@@ -395,8 +396,10 @@ module.exports = (function() { ...@@ -395,8 +396,10 @@ module.exports = (function() {
query.push(SqlGenerator.getJoinClause(model, options.include[i])); query.push(SqlGenerator.getJoinClause(model, options.include[i]));
} }
} }
if(options.hasOwnProperty('where')){
console.log(query); query.push(this.getWhereConditions(options.where, model.name, model, options));
}
//console.log(query);
return query.join(' ') + ';'; return query.join(' ') + ';';
}, },
/** /**
...@@ -483,8 +486,18 @@ module.exports = (function() { ...@@ -483,8 +486,18 @@ module.exports = (function() {
/* /*
Takes something and transforms it into values of a where condition. Takes something and transforms it into values of a where condition.
*/ */
getWhereConditions: function(smth, tableName, factory, options, prepend) { /*
throwMethodUndefined('getWhereConditions'); Takes something and transforms it into values of a where condition.
*/
getWhereConditions: function(smth, tableName, model, options, prepend) {
//console.log('where:', model);
//console.log('logic', smth);
if(!smth){
return SqlGenerator.getWhereClause(tableName, model, options);
}else{
return '';
}
}, },
prependTableNameToHash: function(tableName, hash) { prependTableNameToHash: function(tableName, hash) {
......
...@@ -490,14 +490,26 @@ module.exports = { ...@@ -490,14 +490,26 @@ module.exports = {
var primaryKey = ''; var primaryKey = '';
for(var key in model.rawAttributes){ for(var key in model.rawAttributes){
if(model.rawAttributes[key].primaryKey){ if(model.rawAttributes[key].primaryKey){
primaryKey = key; primaryKey = quoteIdentifier(key);
break; break;
} }
} }
console.log(include.association.foreignKey); var joinType = include.required ? 'INNER JOIN' : 'LEFT OUTER JOIN';
console.log(primaryKey);
//for(var i = 0; i < ) var joinTable = include.as ? include.as : include.model.name;
var joinType = include.required ? ' INNER JOIN ' : ' LEFT OUTER JOIN '; joinTable = quoteIdentifier(joinTable);
var tableName = quoteIdentifier(model.name);
//console.log(include);
return [
joinType,
quoteIdentifier(include.model.tableName),
'AS', joinTable,
'ON', tableName + '.' + primaryKey,
'=', joinTable + '.' + quoteIdentifier(include.association.foreignKey)
].join(' ');
},
getWhereClause: function(tableName, model, options){
//console.log('my model:', model);
} }
}; };
......
...@@ -689,7 +689,6 @@ module.exports = (function() { ...@@ -689,7 +689,6 @@ module.exports = (function() {
} }
}).then(function() { }).then(function() {
expandIncludeAll.call(this, options); expandIncludeAll.call(this, options);
if (options.hooks) { if (options.hooks) {
return this.runHooks('beforeFindAfterExpandIncludeAll', options); return this.runHooks('beforeFindAfterExpandIncludeAll', options);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!