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

Commit b5bec0c6 by Mick Hansen

fix(sql): support nested $col, closes #4849

1 parent e92577ee
# Next # Next
- [FIXED] Model.aggregate methods now support attributes and where conditions with fields. [#4935](https://github.com/sequelize/sequelize/issues/4935) - [FIXED] Model.aggregate methods now support attributes and where conditions with fields. [#4935](https://github.com/sequelize/sequelize/issues/4935)
- [FIXED] Don't overwrite options.foreignKey in associations [#4927](https://github.com/sequelize/sequelize/pull/4927) - [FIXED] Don't overwrite options.foreignKey in associations [#4927](https://github.com/sequelize/sequelize/pull/4927)
- [FIXED] Support nested `$col` keys. [#4849](https://github.com/sequelize/sequelize/issues/4849)
# 3.14.1 # 3.14.1
- [FIXED] Issue with transaction options leaking and certain queries running outside of the transaction connection. - [FIXED] Issue with transaction options leaking and certain queries running outside of the transaction connection.
......
...@@ -2185,7 +2185,16 @@ var QueryGenerator = { ...@@ -2185,7 +2185,16 @@ var QueryGenerator = {
} else if (value && value.$raw) { } else if (value && value.$raw) {
value = value.$raw; value = value.$raw;
} else if (value && value.$col) { } else if (value && value.$col) {
value = value.$col.split('.').map(this.quoteIdentifier.bind(this)).join('.'); value = value.$col.split('.');
if (value.length > 2) {
value = [
value.slice(0, -1).join('.'),
value[value.length - 1]
];
}
value = value.map(this.quoteIdentifier.bind(this)).join('.');
} else { } else {
var escapeValue = true; var escapeValue = true;
...@@ -2225,7 +2234,16 @@ var QueryGenerator = { ...@@ -2225,7 +2234,16 @@ var QueryGenerator = {
if (key._isSequelizeMethod) { if (key._isSequelizeMethod) {
key = this.handleSequelizeMethod(key); key = this.handleSequelizeMethod(key);
} else if (Utils.isColString(key)) { } else if (Utils.isColString(key)) {
key = key.substr(1, key.length - 2).split('.').map(this.quoteIdentifier.bind(this)).join('.'); key = key.substr(1, key.length - 2).split('.');
if (key.length > 2) {
key = [
key.slice(0, -1).join('.'),
key[key.length - 1]
];
}
key = key.map(this.quoteIdentifier.bind(this)).join('.');
prefix = false; prefix = false;
} else { } else {
key = this.quoteIdentifier(key); key = this.quoteIdentifier(key);
......
...@@ -1987,7 +1987,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1987,7 +1987,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
describe('sum', function() { describe('sum', function() {
beforeEach(function() { beforeEach(function() {
var self = this;
this.UserWithAge = this.sequelize.define('UserWithAge', { this.UserWithAge = this.sequelize.define('UserWithAge', {
age: Sequelize.INTEGER, age: Sequelize.INTEGER,
order: Sequelize.INTEGER, order: Sequelize.INTEGER,
......
...@@ -341,6 +341,12 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -341,6 +341,12 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
}, { }, {
default: '[organization].[id] = [user].[organizationId]' default: '[organization].[id] = [user].[organizationId]'
}); });
testsql('$offer.organization.id$', {
$col: 'offer.user.organizationId'
}, {
default: '[offer.organization].[id] = [offer.user].[organizationId]'
});
}); });
suite('$gt', function () { suite('$gt', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!