Skip to content

Commit

Permalink
docs(getters-setters-virtuals): fix typos (#13074 #12811 #12655)
Browse files Browse the repository at this point in the history
Co-authored-by: sliterok <korobatov2011@yandex.ru>
Co-authored-by: William Gurzoni <william_luizat@hotmail.com>
  • Loading branch information
3 people committed Mar 10, 2021
1 parent 2990118 commit 801caa3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/manual/core-concepts/getters-setters-virtuals.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const User = sequelize.define('user', {
username: {
type: DataTypes.STRING,
get() {
const rawValue = this.getDataValue(username);
const rawValue = this.getDataValue('username');
return rawValue ? rawValue.toUpperCase() : null;
}
}
Expand All @@ -27,10 +27,10 @@ This getter, just like a standard JavaScript getter, is called automatically whe
```js
const user = User.build({ username: 'SuperUser123' });
console.log(user.username); // 'SUPERUSER123'
console.log(user.getDataValue(username)); // 'SuperUser123'
console.log(user.getDataValue('username')); // 'SuperUser123'
```

Note that, although `SUPERUSER123` was logged above, the value truly stored in the database is still `SuperUser123`. We used `this.getDataValue(username)` to obtain this value, and converted it to uppercase.
Note that, although `SUPERUSER123` was logged above, the value truly stored in the database is still `SuperUser123`. We used `this.getDataValue('username')` to obtain this value, and converted it to uppercase.

Had we tried to use `this.username` in the getter instead, we would have gotten an infinite loop! This is why Sequelize provides the `getDataValue` method.

Expand All @@ -55,7 +55,7 @@ const User = sequelize.define('user', {
```js
const user = User.build({ username: 'someone', password: 'NotSo§tr0ngP4$SW0RD!' });
console.log(user.password); // '7cfc84b8ea898bb72462e78b4643cfccd77e9f05678ec2ce78754147ba947acc'
console.log(user.getDataValue(password)); // '7cfc84b8ea898bb72462e78b4643cfccd77e9f05678ec2ce78754147ba947acc'
console.log(user.getDataValue('password')); // '7cfc84b8ea898bb72462e78b4643cfccd77e9f05678ec2ce78754147ba947acc'
```

Observe that Sequelize called the setter automatically, before even sending data to the database. The only data the database ever saw was the already hashed value.
Expand Down

0 comments on commit 801caa3

Please sign in to comment.