Why can't I set attribute directly on instance when in hooks?
- Ngôn ngữ chính
- JavaScript
- Star
- 2k
- Fork
- 238
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I want to do something like:
```
var Passport = db.define('passport', {
password: String, // password hashed
})
Passport.validatesLengthOf('password', {min: 6});
Passport.afterValidate = function() {
this.password = Passport.hash(this.password)
}
```
But actually, I have to do
```
Passport.afterValidate = function(next, data) {
data.password = Passport.hash(data.password)
next()
}
```
This is not well documented, and it takes me quite a while to figure out what's going on.
I'm just curious, why not just allow people to set instance attribute directly, instead of passing `data` round and round?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Look at the ORM's hook implementation, likely in lib/hooks.js or similar, to understand how afterValidate receives data. Examine the instance context and data parameter handling. Check existing tests for hooks to see the expected behavior. The fix involves modifying the hook execution to allow direct instance attribute assignment or improving documentation.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, nodejs
- Lĩnh vực
- backend, databases
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100