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
gorm (v1.22.4) problem #282
Comments
if you use const query = `
INSERT INTO "table_test" ("id","name")
VALUES"` to const query = `INSERT INTO "table_test" ("id","name") VALUES"` |
I have the same issue. Did you find a solution yet? Interestingly it seems to be an issue if all fields are provided into the create function or there's something like
Once I uncomment the
it works. And I don't know why that should change anything. |
Please post some example code working on the Go Playground. Here is a template. |
When you set defaults with the gorm struct tag, gorm does some things that you don't always expect. (https://github.com/go-gorm/gorm/blob/master/callbacks/create.go#L207-L295). The order of struct fields and the columns in the sql statement don't always line up, if the struct fields is nil it won't be passed as an argument to the query, and depending on your dialect it may change from an exec (requires sqlmock.ExpectExec) to a query (requires sqlmock.ExpectQuery) and the sql statement might have extra clauses added to it. (in sqlserver a default fields adds Also, don't use regexp.QuoteMeta with the sqlmock.QueryMatcherEqual matcher. That could also be the reason because QuoteMeta with quote your ()'s and that will never match exactly with the actual query. |
Hello,
I am having a problem when I working with gorm v2. I have tried every solution and I could find but none worked.
gorm version: 1.22.4
sqlmock version: v1.5.0
This is my code:
The error:
Thanks
The text was updated successfully, but these errors were encountered: