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

Commit 10cfe11f by David Morton Committed by Mick Hansen

Closes #5985 - Cannot query a custom-named field when offsetting, ordering and u…

…sing hasMany simultaneously (v3 pull request) (#5996)

* Closes #5985 - Cannot query a custom-named field when offsetting, ordering and including hasMany simultaneously.

* Attempting to fix BOM marks
1 parent 208c48fe
# Future
- [FIXED] Fixed an issue where custom-named model fields break when offsetting, ordering, and including hasMany simultaneously. [#5985] (https://github.com/sequelize/sequelize/issues/5985)
# 3.23.3 # 3.23.3
- [FIXED] Pass ResourceLock instead of raw connection in MSSQL disconnect handling - [FIXED] Pass ResourceLock instead of raw connection in MSSQL disconnect handling
......
...@@ -1571,8 +1571,20 @@ var QueryGenerator = { ...@@ -1571,8 +1571,20 @@ var QueryGenerator = {
} }
} }
var hadSubquery = false;
if (subQuery && (Array.isArray(t) && !(t[0] instanceof Model) && !(t[0].model instanceof Model))) { if (subQuery && (Array.isArray(t) && !(t[0] instanceof Model) && !(t[0].model instanceof Model))) {
subQueryOrder.push(this.quote(t, model)); subQueryOrder.push(this.quote(t, model));
hadSubquery = true;
}
if (hadSubquery) {
for (var name in model.attributes) {
var attribute = model.attributes[name];
if (attribute.field && attribute.field === t[0]) {
t[0] = attribute.fieldName;
}
}
} }
mainQueryOrder.push(this.quote(t, model)); mainQueryOrder.push(this.quote(t, model));
......
...@@ -10,6 +10,58 @@ var chai = require('chai') ...@@ -10,6 +10,58 @@ var chai = require('chai')
describe(Support.getTestDialectTeaser('Model'), function() { describe(Support.getTestDialectTeaser('Model'), function() {
describe('findAll', function () { describe('findAll', function () {
describe('order', function () { describe('order', function () {
it('should work on a model field whose name doesnt match the database, while offsetting and including a hasMany.', function() {
var Foo = current.define('foo', {
fooId: {
field: 'foo_id',
type: DataTypes.UUID,
primaryKey: true
},
baseNumber: {
field: 'base_number',
type: DataTypes.STRING(25)
}
}, {
timestamps: false
}),
Bar = current.define('bar', {
barId: {
field: 'bar_id',
type: DataTypes.UUID,
primaryKey: true
},
fooId: {
field: 'foo_id',
type: DataTypes.UUID,
allowNull: false
}
}, {
timestamps: false
});
Foo.hasMany(Bar, {foreignKey: 'foo_id', as: 'bars'});
return current.sync({force: true})
.then(function () {
var options = {
include: [
{
model: Bar, as: 'bars'
}
],
offset: 0,
limit: 50,
order: [['base_number', 'ASC']]
};
return Foo.findAll(options).then(function () {
console.log('success!');
}, function (err) {
throw err;
});
});
});
describe('Sequelize.literal()', function () { describe('Sequelize.literal()', function () {
beforeEach(function () { beforeEach(function () {
this.User = this.sequelize.define('User', { this.User = this.sequelize.define('User', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!