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

Commit 81f917ea by Mick Hansen

restore BC

1 parent cea01f83
......@@ -437,7 +437,7 @@ module.exports = (function() {
options.attributes = optAttributes.join(', ')
}
var conditionalJoins = options.hasMultiAssociation && (options.limit || options.offset) && this.getConditionalJoins(options, factory),
var conditionalJoins = ((options.hasMultiAssociation && (options.limit || options.offset)) || !options.include) && this.getConditionalJoins(options, factory),
query;
if (conditionalJoins) {
......@@ -449,7 +449,7 @@ module.exports = (function() {
}
if (options.hasOwnProperty('where')) {
options.where = this.getWhereConditions(options.where, tableName, factory)
options.where = this.getWhereConditions(options.where, tableName, factory, options)
query += " WHERE " + options.where
}
......@@ -535,13 +535,13 @@ module.exports = (function() {
/*
Takes something and transforms it into values of a where condition.
*/
getWhereConditions: function(smth, tableName, factory) {
getWhereConditions: function(smth, tableName, factory, options) {
var result = null
, where = {}
if (Utils.isHash(smth)) {
smth = Utils.prependTableNameToHash(tableName, smth)
result = this.hashToWhereConditions(smth, factory)
result = this.hashToWhereConditions(smth, factory, options)
} else if (typeof smth === 'number') {
var primaryKeys = !!factory ? Object.keys(factory.primaryKeys) : []
if (primaryKeys.length > 0) {
......@@ -601,7 +601,7 @@ module.exports = (function() {
return dao;
},
isAssociationFilter: function(filterStr, dao){
isAssociationFilter: function(filterStr, dao, options){
if(!dao){
return false;
}
......@@ -621,7 +621,7 @@ module.exports = (function() {
}) && dao.rawAttributes.hasOwnProperty(attributePart);
},
getAssociationFilterColumn: function(filterStr, dao){
getAssociationFilterColumn: function(filterStr, dao, options){
var associationParts = filterStr.split('.')
, attributePart = associationParts.pop()
, self = this
......@@ -631,10 +631,15 @@ module.exports = (function() {
associationParts.forEach(function (attribute) {
association = self.findAssociation(attribute, dao)
dao = association.target;
if (options.include) {
keyParts.push(association.as || association.options.as || dao.tableName)
}
})
if (options.include) {
return this.quoteIdentifier(keyParts.join('.')) + '.' + this.quote(attributePart);
}
return this.quoteIdentifiers(dao.tableName + '.' + attributePart);
},
getConditionalJoins: function(options, originalDao){
......@@ -648,7 +653,7 @@ module.exports = (function() {
, attributePart = associationParts.pop()
, dao = originalDao
if (self.isAssociationFilter(filterStr, dao)) {
if (self.isAssociationFilter(filterStr, dao, options)) {
associationParts.forEach(function (attribute) {
var association = self.findAssociation(attribute, dao);
......@@ -695,7 +700,7 @@ module.exports = (function() {
Takes a hash and transforms it into a mysql where condition: {key: value, key2: value2} ==> key=value AND key2=value2
The values are transformed by the relevant datatype.
*/
hashToWhereConditions: function(hash, dao) {
hashToWhereConditions: function(hash, dao, options) {
var result = []
for (var key in hash) {
......@@ -703,8 +708,8 @@ module.exports = (function() {
, _key
, _value = null
if(this.isAssociationFilter(key, dao)){
_key = key = this.getAssociationFilterColumn(key, dao);
if(this.isAssociationFilter(key, dao, options)){
_key = key = this.getAssociationFilterColumn(key, dao, options);
} else {
_key = this.quoteIdentifiers(key)
}
......
......@@ -46,12 +46,12 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
Task.findAll({
where: {
'project.user.username': 'leia'
},
}/*,
include: [
{model: Project, include: [
User
]}
]
]*/
}).done(function(err, tasks){
expect(err).not.to.be.ok
......@@ -112,12 +112,12 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
where: {
'project.user.username': 'leia',
'project.user.id': 1
},
}/*,
include: [
{model: Project, include: [
User
]}
]
]*/
}).success(function(tasks){
try{
expect(tasks.length).to.be.equal(2);
......@@ -174,12 +174,12 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
User.findAll({
where: {
'projects.tasks.title': 'fight empire'
},
}/*,
include: [
{model: Project, include: [
Task
]}
]
]*/
}).done(function(err, users){
try{
expect(users.length).to.be.equal(1);
......@@ -223,10 +223,10 @@ describe(Support.getTestDialectTeaser("Multiple Level Filters"), function() {
User.findAll({
where: {
'projects.title': 'republic'
},
}/*,
include: [
{model: Project}
]
]*/
}).success(function(users){
try{
expect(users.length).to.be.equal(1);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!