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

Commit e2dd7da9 by Mick Hansen

fix(include): hasMany.separate should use foreign key field for grouped limit an…

…d only apply grouped limit if more than one instance being requested
1 parent 5a36157e
...@@ -283,10 +283,10 @@ HasMany.prototype.get = function(instances, options) { ...@@ -283,10 +283,10 @@ HasMany.prototype.get = function(instances, options) {
return instance.get(association.source.primaryKeyAttribute, {raw: true}); return instance.get(association.source.primaryKeyAttribute, {raw: true});
}); });
if (options.limit) { if (options.limit && instances.length > 1) {
options.groupedLimit = { options.groupedLimit = {
limit: options.limit, limit: options.limit,
on: association.foreignKey, on: association.foreignKeyField,
values: values values: values
}; };
......
...@@ -124,10 +124,15 @@ if (current.dialect.supports.groupedLimit) { ...@@ -124,10 +124,15 @@ if (current.dialect.supports.groupedLimit) {
it('should run a hasMany association with limit in a separate query', function () { it('should run a hasMany association with limit in a separate query', function () {
var User = this.sequelize.define('User', {}) var User = this.sequelize.define('User', {})
, Task = this.sequelize.define('Task', {}) , Task = this.sequelize.define('Task', {
userId: {
type: DataTypes.INTEGER,
field: 'user_id'
}
})
, sqlSpy = sinon.spy(); , sqlSpy = sinon.spy();
User.Tasks = User.hasMany(Task, {as: 'tasks'}); User.Tasks = User.hasMany(Task, {as: 'tasks', foreignKey: 'userId'});
return this.sequelize.sync({force: true}).then(function () { return this.sequelize.sync({force: true}).then(function () {
return Promise.join( return Promise.join(
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!