Skip to content
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

Merged
merged 3 commits into from
May 9, 2024

Conversation

awrichar
Copy link
Contributor

@awrichar awrichar commented May 7, 2024

No description provided.

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

@peterbroadhurst peterbroadhurst left a 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]>
@awrichar awrichar merged commit dab0027 into hyperledger:main May 9, 2024
2 checks passed
@awrichar awrichar deleted the after-load branch May 9, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants