Ability to add getter and setter methods to Model object#70
Conversation
|
can you please provide an example how to use it? |
|
I prefer like in the examples. set a object like this var myE = entity.build({ or var myE = entity.build({}); But if you have to put some logic, u can create the Set method |
|
i finally understood what this ticket is about :D i do like |
|
a test would be great |
|
Created an example for this feature: https://gist.github.com/2964211 |
|
I tried this code but I couldn't get it to work. Is this all the code that's needed..? |
|
Any chance of getting this pulled? Since Sequelize recommends using INTEGER for holding money as cents, I wrote this model, thinking that this patch had already been accepted. module.exports = function(sequelize, DataTypes){
return sequelize.define('Variant', {
color: {
type: DataTypes.STRING },
size: {
type: DataTypes.STRING },
listPriceCents: {
type: DataTypes.INTEGER,
allowNull: false },
salePriceCents: {
type: DataTypes.INTEGER,
allowNull: false },
childSku: {
type: DataTypes.STRING,
unique: true,
allowNull: false },
},
{ getterMethods: {
listPrice: function() {
return this.listPriceCents / 100
},
salePrice: function() {
return this.salePriceCents / 100
}}
,
setterMethods: {
listPrice: function(list) {
this.listPriceCents = list * 100
},
salePrice: function(sale) {
this.salePriceCents = sale * 100
}}
// ProductId
} )} |
|
FYI, here's some context on why using setter and getter methods on top of Integer is a better idea than using floats for currency: http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency |
|
+1 also waiting for this. |
|
Realized the commit was obsolete, ended up writing a fresh one + a test. See pull request: https://github.com/sdepold/sequelize/pull/393 |
|
as this is quite old. I will check the PR #538 |
Simple ability to add getter and setters for properties to Models. Uses the same syntax as classMethods and instanceMethods.