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

Commit d1eebaba by Mick Hansen

Merge pull request #5093 from sushantdhiman/fix-4856

Fix #4856 : Attributes from multiple scopes doesn't merge
2 parents 2f7c717f c3edc317
# Future # Future
- [FIXED] attributes from multiple scopes does not merge [#4856](https://github.com/sequelize/sequelize/issues/4856)
- [FIXED] Support Unicode strings in mssql [#3752](https://github.com/sequelize/sequelize/issues/3752) - [FIXED] Support Unicode strings in mssql [#3752](https://github.com/sequelize/sequelize/issues/3752)
# 3.15.1 # 3.15.1
......
...@@ -1193,7 +1193,7 @@ Model.prototype.scope = function(option) { ...@@ -1193,7 +1193,7 @@ Model.prototype.scope = function(option) {
_.assign(self.$scope, scope, function scopeCustomizer(objectValue, sourceValue, key) { _.assign(self.$scope, scope, function scopeCustomizer(objectValue, sourceValue, key) {
if (key === 'where') { if (key === 'where') {
return Array.isArray(sourceValue) ? sourceValue : _.assign(objectValue || {}, sourceValue); return Array.isArray(sourceValue) ? sourceValue : _.assign(objectValue || {}, sourceValue);
} else if (key === 'include' && Array.isArray(objectValue) && Array.isArray(sourceValue)) { } else if ( (['attributes','include'].indexOf(key) >= 0) && Array.isArray(objectValue) && Array.isArray(sourceValue)) {
return objectValue.concat(sourceValue); return objectValue.concat(sourceValue);
} }
......
'use strict';
/* jshint -W030 */
/* jshint -W110 */
var chai = require('chai')
, Sequelize = require('../../../index')
, expect = chai.expect
, Support = require(__dirname + '/../support');
describe(Support.getTestDialectTeaser('Model'), function() {
describe('scope', function () {
beforeEach(function () {
this.ScopeMe = this.sequelize.define('ScopeMe', {
username: Sequelize.STRING,
email: Sequelize.STRING,
access_level: Sequelize.INTEGER,
other_value: Sequelize.INTEGER
}, {
scopes: {
lowAccess: {
attributes: ['other_value', 'access_level'],
where: {
access_level: {
lte: 5
}
}
},
withName: {
attributes: ['username']
}
}
});
return this.sequelize.sync({force: true}).then(function() {
var records = [
{username: 'tony', email: 'tony@sequelizejs.com', access_level: 3, other_value: 7},
{username: 'tobi', email: 'tobi@fakeemail.com', access_level: 10, other_value: 11},
{username: 'dan', email: 'dan@sequelizejs.com', access_level: 5, other_value: 10},
{username: 'fred', email: 'fred@foobar.com', access_level: 3, other_value: 7}
];
return this.ScopeMe.bulkCreate(records);
}.bind(this));
});
it('should be able to merge attributes as array', function () {
return this.ScopeMe.scope('lowAccess','withName').findOne()
.then(function(record){
expect(record.other_value).to.exist;
expect(record.username).to.exist;
expect(record.access_level).to.exist;
});
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!