1602 / 1602/jugglingdb

Why can't I set attribute directly on instance when in hooks?

オープン
#385 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
2k
フォーク
238
PR マージ指標
30日以内にマージされた PR はありません

説明

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?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, nodejs
領域
backend, databases
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。