-
-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty model on BeforeInsert hook #24
Comments
Because Bun also works with slice-based models, e.g. Overall it is best to only use hooks as a last resort when everything else fails. In your case you should create |
If I will create function |
Another case... |
Better example for https://bun.uptrace.dev/guide/hooks.html#disclaimer func UpdateUser(ctx context.Context, query bun.UpdateQuery, user *User) error { ... }
func InsertUser(ctx context.Context, query bun.InsertQuery, user *User) error { ... } |
I am not sure sure how you managed transactions with hooks, but that does not sound right :) A better solution would be to create a common interface for tx := db.Begin()
InsertUser(ctx, tx)
InsertProfile(ctx, tx)
tx.Commit() I guess Bun must provide such interface.
Ideally, yes. Practically you should not use hooks for such common things like transactions and validation. |
|
My User model
Why I must use query.GetModel() all time instead use self object?
I have this code:
I have hook chains in my models and all was good)
I can create long hook-chains for each models by logic.
After update, I must all time use
query.Get Model().Value().(*SomeModel)
boilerplate... :( and must thinking about type casting.The text was updated successfully, but these errors were encountered: