Skip to content

Use classes for examples in model definition docs - #6439

Closed
felixfbecker wants to merge 1 commit into
sequelize:masterfrom
felixfbecker:es6-model-definition-docs
Closed

felixfbecker wants to merge 1 commit into
sequelize:masterfrom
felixfbecker:es6-model-definition-docs

Conversation

@felixfbecker

Copy link
Copy Markdown
Contributor

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.

@felixfbecker
felixfbecker force-pushed the es6-model-definition-docs branch from 4b74344 to 76590ab Compare August 15, 2016 10:04
return this.getDataValue('title');
class Transaction extends Sequelize.Model {
get status() {
return this._status.toLowerCase();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to add an underscore feels ugly to me - I'd rather we advertise getDataValue for getters named the same as their property

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDataValue seems cleaner than _status, Once you finish implementing #6270 we can decide how to change docs to adopt to new structure.

@felixfbecker felixfbecker added the docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference. label Aug 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants