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
Clause.(clause.Returning{}) dosen't work in a delete opertaion #85
Comments
Can you create a pr in go-gorm/playground to describe it ? |
@a631807682 OK, I'll try it. |
@a631807682 Hello, I think I reproduced the problem I had in this pr go-gorm/playground#503 . But at the same time I encountered a new problem. When I try to create a new 'process', the primaryKey is blank, but I have set it autoIncrement and not null. |
@Zacama I checked the playground and test is passed. |
@a631807682 |
returning may need to be specified depending on the version, need confirm. @Zacama I didn't try it, but you should be able to use like this callbacks.RegisterDefaultCallbacks(db, &callbacks.Config{
CreateClauses: []string{"INSERT", "VALUES", "ON CONFLICT", "RETURNING"},
QueryClauses: mysql.QueryClauses,
UpdateClauses: mysql.UpdateClauses,
DeleteClauses: mysql.DeleteClauses,
}) |
@a631807682 I want to confirm that do you mean I should able to use like this?
|
@Zacama yes |
@a631807682 It returns a lot of warning ... I find that it has been called in gorm.Open() |
how about? db, _ := gorm.Open(mysql.Open(dsn))
createCallback := db.Callback().Create()
createCallback.Clauses = []string{"INSERT", "VALUES", "ON CONFLICT", "RETURNING"} |
@a631807682 yeah, It can print right rawsql now. |
@a631807682 Really, thank you very very much for helping me solve this problem😊. I achieved my goal. I don't quite understand the process of closing the issue. If I can close this issue, I'm ready to close it. |
@Zacama I think we can keep it open and wait for someone to implement it. |
@a631807682 OK, we keep it. |
Clause.(clause.Returning{}) dosen't active in a delete opertaion
Version: gorm 1.23.8 and golang 1.18.3
Sorry for my poor English...
I try to use Clause.(clause.Returning{}) to returning the obj which has been deleted. But It doesn't work.
At first, I thought the database dose not support Returning. So I try it by raw sql, it works.
Then, I try to find the problem by reading source code and debug it. Limited by my skill level, I can only find out the final raw sql (generated by gorm) does not contain
RETURNING
.Partof callback.go/Execute function
statement.go/AddClause function
But it can be seen from the screenshot that
RETURNING
is added to db.Statement.Clauses map but it seems like no subsequent code to use it.I don't know which step is wrong. If anyone could help me take a look, it would be greatly appreciated.
The document you expected this should be explained
Expected answer
Just want got the return successfully.
The text was updated successfully, but these errors were encountered: