sequelize: Problem with getter and attributes
I have a model defined roughly as:
sequelize.define("modelName", {
id : {
type : DataTypes.STRING,
field : "mn_id",
primaryKey : true,
get : function() {
let id = this.getDataValue("id");
return id.slice(7);
},
}
});
And I am running a find all against this model like such:
ss.db.AdjustType.findAll({
attributes : [["mn_id", "name"]],
});
this throws an error because it is attempting to use the getter but the data value is named “name” instead of “id”, so it fails. Is there a way to map these values so the getter works?
I am using version 3.10.0
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16 (10 by maintainers)
I’m not sure what has been decided about that issue. Customs getters still are called even if a specific list of attributes is set in a
findAll({})
call for instance (not dealing with VIRTUAL types here). So what, do I have to check in every getter for undefined values ?!Something to note in deciding whether to approach solution C. Even were you to follow solution B, you’d still end up with un-wanted properties in your resulting object
Seems to contradict expected behavior as outlined https://github.com/sequelize/sequelize/pull/1460