Repository navigation
Use classes for examples in model definition docs - #6439
felixfbecker wants to merge 1 commit into
Conversation
4b74344 to
76590ab
Compare
| return this.getDataValue('title'); | ||
| class Transaction extends Sequelize.Model { | ||
| get status() { | ||
| return this._status.toLowerCase(); |
There was a problem hiding this comment.
Having to add an underscore feels ugly to me - I'd rather we advertise getDataValue for getters named the same as their property
There was a problem hiding this comment.
Personally I dislike getDataValue because you cannot get any compile-time checks or IntelliSense for the attribute name, as it is a string.
But the primary motivation was that #6270 might change instances so that attributes are saved on the instance directly instead of in dataValues (and we only keep previousDataValues). There are a couple of reasons why this would be good, we wouldn't need getters and setters for the attributes anymore, which means better performance and that an instance can be treated like a plain simple instance of the model class. You can for example use the delete operator properly, which previously only deleted the getter/setter.
Prefixing the attribute with an underscore is the established pattern for implementing proxy accessors. Basically the actual property is private (and by convention prefixed with underscore) while the setters/getters are public.
For example http://stackoverflow.com/a/12850536/4208018 (it's TS but the same applies to ES6)
There was a problem hiding this comment.
getDataValue seems cleaner than _status, Once you finish implementing #6270 we can decide how to change docs to adopt to new structure.
This is my proposal for the docs with the new style of defining models. I think it is important to get the docs out now so we can get feedback on the proposed syntax.