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

Commit 81f917ea by Mick Hansen

restore BC

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