-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add custom ID field and AfterLoad hook #137
Conversation
Signed-off-by: Andrew Richardson <[email protected]>
Allows mutating loaded objects after loading them from the database. Signed-off-by: Andrew Richardson <[email protected]>
@@ -728,6 +740,12 @@ func (c *CrudBase[T]) getManyScoped(ctx context.Context, tableFrom string, fi *f | |||
if err != nil { | |||
return nil, nil, err | |||
} | |||
if c.AfterLoad != nil { | |||
err = c.AfterLoad(ctx, inst) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels still a bit weird that these fields will not get propagated to an object passed into Insert
or Update
.
Don't think we can do anything about it, but wonder if any health warnings are needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ends up being most useful for performing final validation and formatting on the whole object after it is loaded (for things that cannot be done in GetFieldPtr). I can add a note to this effect.
It is less useful for purely generated fields, for the reason you noted. Not sure if I need to add additional comments to specifically discourage that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my unit test is now misleading in this regard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment and tweaked the unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with one comment to consider @awrichar
Signed-off-by: Andrew Richardson <[email protected]>
No description provided.