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

gorm v2组查询时,使用.Table与不使用生成的sql不一样 #636

Open
ZHOUXING1997 opened this issue Aug 8, 2023 · 0 comments
Open
Assignees

Comments

@ZHOUXING1997
Copy link

GORM Playground Link

#1

Description

gorm v2组查询时,使用.Table与不使用生成的sql不一样
This parameter is used to query the gorm v2 group. Table is not the same as sql generated without using it

`
db, _ := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})

pizzas := struct {
}{}
db.Table("microloan.account_base").Where(
db.Where("pizza = ?", "pepperoni").Where(db.Where("size = ?", "small").Or("size = ?", "medium")),
).Or(
db.Where("pizza = ?", "hawaiian").Where("size = ?", "xlarge"),
).Find(&pizzas)

db = db.Table("microloan.account_base")
db.Where(
db.Where("pizza = ?", "pepperoni").Where(db.Where("size = ?", "small").Or("size = ?", "medium")),
).Or(
db.Where("pizza = ?", "hawaiian").Where("size = ?", "xlarge"),
).Find(&pizzas)
`

this not use
2023/08/08 15:06:09
[0.122ms] [rows:0] SELECT * FROM microloan.account_base WHERE (pizza = "pepperoni" AND (size = "small" OR size = "medium")) OR (pizza = "hawaiian" AND size = "xlarge")

this used
2023/08/08 15:06:09
[0.025ms] [rows:0] SELECT * FROM microloan.account_base WHERE ((pizza = "pepperoni" AND size = "small" OR size = "medium") AND pizza = "hawaiian" AND size = "xlarge")

I need to specify 'database.table' using 'table()', but I want the result of the first.
Or is there another way to specify a database?

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

No branches or pull requests

2 participants