Open alkuma opened 4 months ago
It seems stmt.Table="department"
is accidentally cached here
https://github.com/go-gorm/gorm/blob/9d370bcb3ec9055b6292da5211f4eaee2458f520/statement.go#L492
after stmt.Schema, err = schema.ParseWithSpecialTableName(...)
:
err == nil
stmt.Table == "department"
so the if block with stmt.Table = stmt.Schema.Table
is skipped, and stmt.Table
remains "department"
I think this can be fixed by change
if stmt.Schema, err = schema.ParseWithSpecialTableName(value, stmt.DB.cacheStore, stmt.DB.NamingStrategy, specialTableName); err == nil && stmt.Table == "" {
to
if stmt.Schema, err = schema.ParseWithSpecialTableName(value, stmt.DB.cacheStore, stmt.DB.NamingStrategy, specialTableName); err == nil {
@jinzhu what do you think?
…action
Explain your user case and expected results
I am attempting to modify two tables within a transaction. However the second table insert within the transaction thows an error which implies that gorm is still keeping the old table name in its state despite calling
Model()
with the new model the second time.This finally leads me to an error
whereas this query should have been
There are many other errors in my use case but dropping the individual items one by one, this is the first one.