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

Commit e9bbe8db by Mick Hansen

fix: Use unescaped tableName for groupedLimit selects, closes #6131

1 parent cca388be
......@@ -1390,7 +1390,7 @@ const QueryGenerator = {
where[options.groupedLimit.on] = value;
return '('+this.selectQuery(
table,
tableName,
{
attributes: options.attributes,
limit: options.groupedLimit.limit,
......
......@@ -707,54 +707,6 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), function() {
});
});
it('should be possible to define a hasMany include with grouped limit', function() {
var User = this.sequelize.define('User', {}, {schema: 'account'})
, Task = this.sequelize.define('Task', {
title: DataTypes.STRING
}, {schema: 'account'});
User.Tasks = User.hasMany(Task, {as: 'tasks'});
return this.sequelize.sync({force: true}).then(function () {
return Promise.join(
User.create({
tasks: [
{title: 'b'},
{title: 'd'},
{title: 'c'},
{title: 'a'}
]
}, {
include: [User.Tasks]
}),
User.create({
tasks: [
{title: 'a'},
{title: 'c'},
{title: 'b'}
]
}, {
include: [User.Tasks]
})
);
}).then(function (users) {
return User.findAll({
include: [{ model: Task, limit: 2, as: 'tasks' }],
order: [
['id', 'ASC']
]
}).then(function (result) {
expect(result[0].tasks.length).to.equal(2);
expect(result[0].tasks[0].title).to.equal('b');
expect(result[0].tasks[1].title).to.equal('d');
expect(result[1].tasks.length).to.equal(2);
expect(result[1].tasks[0].title).to.equal('a');
expect(result[1].tasks[1].title).to.equal('c');
});
});
});
it('should be possible to define a belongsTo include as required with child hasMany with limit and aliases', function() {
var User = this.sequelize.define('User', {}, {schema: 'account'})
, Group = this.sequelize.define('Group', {
......
......@@ -374,6 +374,59 @@ if (current.dialect.supports.groupedLimit) {
});
});
});
it('should work with two schema models in a hasMany association', function() {
var User = this.sequelize.define('User', {}, {schema: 'archive'})
, Task = this.sequelize.define('Task', {
title: DataTypes.STRING
}, {schema: 'archive'});
User.Tasks = User.hasMany(Task, {as: 'tasks'});
return this.sequelize.dropAllSchemas().then(() => {
return this.sequelize.createSchema('archive').then(() => {
return this.sequelize.sync({force: true}).then(() => {
return Promise.join(
User.create({
tasks: [
{title: 'b'},
{title: 'd'},
{title: 'c'},
{title: 'a'}
]
}, {
include: [User.Tasks]
}),
User.create({
tasks: [
{title: 'a'},
{title: 'c'},
{title: 'b'}
]
}, {
include: [User.Tasks]
})
);
}).then((users) => {
return User.findAll({
include: [{ model: Task, limit: 2, as: 'tasks' }],
order: [
['id', 'ASC']
],
logging: console.log
}).then((result) => {
expect(result[0].tasks.length).to.equal(2);
expect(result[0].tasks[0].title).to.equal('b');
expect(result[0].tasks[1].title).to.equal('d');
expect(result[1].tasks.length).to.equal(2);
expect(result[1].tasks[0].title).to.equal('a');
expect(result[1].tasks[1].title).to.equal('c');
});
});
});
});
});
});
});
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!