-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
FirstOrCreate runs AfterFind hook and stops on error #4048
Comments
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the |
FYI... I think in FirstOrCreate the AfterFind is called even if there is no rows returned, and if we have any field updation on AfterFind() it gets done too : which gets reciprocated on BeforeCreate/BeforeSave.... I believe this is an unwanted behaviour @jinzhu |
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the |
Firgured out this is a problem with Find as well as FirstOrCreate... Essentially AfterFind should not run if there are no rows affected after find query |
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the |
Fixed, thank you for your report. |
GORM Playground Link
go-gorm/playground#272
Description
The FirstOrCreate should actually check if there are any rows in the db, and if it exists then run AfterFind else create the row first.
In my case however the function returns error because it runs AfterFind() before creating the row, and thus panics "Unknown related entity for entity task : "
It does not run BeforeCreate at all
The text was updated successfully, but these errors were encountered: