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

Commit ff96051e by Mick Hansen

use custom getters in get()

1 parent 5228c35b
Showing with 42 additions and 1 deletions
...@@ -100,6 +100,17 @@ module.exports = (function() { ...@@ -100,6 +100,17 @@ module.exports = (function() {
return this.dataValues[key] return this.dataValues[key]
} }
if (this._hasCustomGetters) {
var values = {}
, key
for (key in this.dataValues) {
if (this.dataValues.hasOwnProperty(key)) {
values[key] = this.get(key)
}
}
return values
}
return this.dataValues return this.dataValues
} }
DAO.prototype.set = function (key, value, options) { DAO.prototype.set = function (key, value, options) {
......
...@@ -137,7 +137,37 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -137,7 +137,37 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
}) })
describe('get', function () { describe('get', function () {
it('should use custom getters in get(key)', function () {
var Product = this.sequelize.define('Product', {
price: {
type: Sequelize.STRING,
get: function() {
return this.dataValues['price'] * 100
}
}
})
var product = Product.build({
price: 10
})
expect(product.get('price')).to.equal(1000)
})
it('should use custom getters in toJSON', function () {
var Product = this.sequelize.define('Product', {
price: {
type: Sequelize.STRING,
get: function() {
return this.dataValues['price'] * 100
}
}
})
var product = Product.build({
price: 10
})
expect(product.toJSON()).to.deep.equal({price: 1000, id: null})
})
}) })
describe('changed', function () { describe('changed', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!