Problem with getter and attributes
See original GitHub issueI 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
Issue Analytics
- State:
- Created 8 years ago
- Comments:16 (10 by maintainers)
Top Results From Across the Web
Why getter and setter methods are evil - InfoWorld
Getter and setter methods (also known as accessors) are dangerous for the same reason that public fields are dangerous: They provide external access...
Read more >Getters and Setters: Manage Attributes in Python
The problem with regular attributes is that they can't have an internal implementation because they're just variables. So, changing an ...
Read more >Avoid getters and setters whenever possible
The argument is that getters/setters and properties VIOLATE ENCAPSULATION by exposing internals as properties rather than mutating through ...
Read more >java - Why getter method doesn't return any object's attribute?
My program should return the different attributes for two different objects. In my main method I set those attributes as the arguments while ......
Read more >3. Properties vs. Getters and Setters | OOP - Python Courses eu
These methods are of course the getter for retrieving the data and the setter for changing the data. According to this principle, the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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