不要怂,就是干,撸起袖子干!

Commit 801caa36 by Shivam Kalra Committed by GitHub

docs(getters-setters-virtuals): fix typos (#13074 #12811 #12655)

Co-authored-by: sliterok <korobatov2011@yandex.ru>
Co-authored-by: William Gurzoni <william_luizat@hotmail.com>
1 parent 29901187
...@@ -15,7 +15,7 @@ const User = sequelize.define('user', { ...@@ -15,7 +15,7 @@ const User = sequelize.define('user', {
username: { username: {
type: DataTypes.STRING, type: DataTypes.STRING,
get() { get() {
const rawValue = this.getDataValue(username); const rawValue = this.getDataValue('username');
return rawValue ? rawValue.toUpperCase() : null; return rawValue ? rawValue.toUpperCase() : null;
} }
} }
...@@ -27,10 +27,10 @@ This getter, just like a standard JavaScript getter, is called automatically whe ...@@ -27,10 +27,10 @@ This getter, just like a standard JavaScript getter, is called automatically whe
```js ```js
const user = User.build({ username: 'SuperUser123' }); const user = User.build({ username: 'SuperUser123' });
console.log(user.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. 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.
...@@ -55,7 +55,7 @@ const User = sequelize.define('user', { ...@@ -55,7 +55,7 @@ const User = sequelize.define('user', {
```js ```js
const user = User.build({ username: 'someone', password: 'NotSo§tr0ngP4$SW0RD!' }); const user = User.build({ username: 'someone', password: 'NotSo§tr0ngP4$SW0RD!' });
console.log(user.password); // '7cfc84b8ea898bb72462e78b4643cfccd77e9f05678ec2ce78754147ba947acc' 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. 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.
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!