I'm not sure if this is a bug in gorm or just missing from documentation for breaking changes between gorm v1 and v2. This problem didn't exist in gorm v1.

When adding where conditions with structs, the table named is fixed to clause.CurrentTable regardless of the struct type. For example:

Where(Model1{ID: 1}).
Where(Model2{ID: 2}).
Where(Model3{ID: 3})

SQL:

wanted: where model1.id = 1 and model2.id = 2 and model3.id = 3
   got: where model1.id = 1 and model1.id = 2 and model1.id = 3

https://github.com/go-gorm/playground/pull/656

Description

I am migrating from gorm v1 to gorm v2 and I found this difference that I don't think is documented in Breaking changes

stmt := DB.Session(&gorm.Session{DryRun: true}).
        Select("*").
        Joins("join users on users.id = pets.user_id").
        Where(&User{Name: "user_name"}).Find(&pets).Statement
expect := "SELECT * FROM `pets` join users on users.id = pets.user_id WHERE `users`.`name` = ? AND `pets`.`deleted_at` IS NULL"
got    := "SELECT * FROM `pets` join users on users.id = pets.user_id WHERE `pets`.`name` = ? AND `pets`.`deleted_at` IS NULL"

Comment From: gabriel-vasile

It seems like the issue was introduced in minor versions of v2 (not between v1 and v2, like I initially thought).

This issue was introduced in 3cd81ff. To me #3382 seems an invalid issue. The problem could have been solved by adding TableName method on RecordInfo, not by hardcoding all Where(Model{}) to the same table specified by Table().