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

Commit c92ae383 by Jan Aagaard Meier

Fix instance.set for virtual attributes

1 parent 156c98ce
...@@ -22,6 +22,9 @@ test: ...@@ -22,6 +22,9 @@ test:
fi fi
endif endif
test-only:
./node_modules/mocha/bin/mocha --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter $(REPORTER) $(TESTS); \
jshint: jshint:
./node_modules/.bin/jshint lib ./node_modules/.bin/jshint lib
......
...@@ -241,7 +241,7 @@ module.exports = (function() { ...@@ -241,7 +241,7 @@ module.exports = (function() {
// Loop and call set // Loop and call set
if (this.options.attributes) { if (this.options.attributes) {
keys = this.options.attributes; keys = this.options.attributes.concat(this.Model._virtualAttributes);
if (this.options && this.options.includeNames) { if (this.options && this.options.includeNames) {
keys = keys.concat(this.options.includeNames); keys = keys.concat(this.options.includeNames);
......
...@@ -324,7 +324,7 @@ describe(Support.getTestDialectTeaser("Model"), function () { ...@@ -324,7 +324,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
return this.sequelize.sync({ force: true }); return this.sequelize.sync({ force: true });
}); });
it('should be ignored in dataValues get', function () { it('should not be ignored in dataValues get', function () {
var user = this.User.build({ var user = this.User.build({
field1: 'field1_value', field1: 'field1_value',
field2: 'field2_value' field2: 'field2_value'
...@@ -356,6 +356,23 @@ describe(Support.getTestDialectTeaser("Model"), function () { ...@@ -356,6 +356,23 @@ describe(Support.getTestDialectTeaser("Model"), function () {
]); ]);
}); });
it("should allow me to store selected values", function () {
var Post = this.sequelize.define('Post', {
text: Sequelize.TEXT,
someBoolean: {
type: Sequelize.VIRTUAL
}
});
return this.sequelize.sync({ force: true}).then(function () {
return Post.bulkCreate([{ text: 'text1' },{ text: 'text2' }]);
}).then(function () {
return Post.find({ attributes: ['id','text',Sequelize.literal('EXISTS(SELECT 1) AS "someBoolean"')] });
}).then(function (post) {
expect(post.get()).to.deep.equal({ id: 1, text: "text1", someBoolean: 1});
});
});
it('should be ignored in create and updateAttributes', function () { it('should be ignored in create and updateAttributes', function () {
return this.User.create({ return this.User.create({
field1: 'something' field1: 'something'
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!