Closed weloe closed 1 year ago
@tangyang9464 @JalinWang @imp2002
The following is my understanding, I hope it can help you.
The reason why db.Table()
cannot execute the specified table name is this line of code:
a.db = db.Scopes(a.casbinRuleTable()).Session(&gorm.Session{})
The default table for the current session is "casbin_rule", although you specify a different table name in the Table()
, it does not work.
You want to operate the user
table, why not use Exec()
directly?
res := db.Exec("insert into user (username,password) values(?,?)", register.Username, register.Password)
As you said, it works.
Alternatively, you can try to create a new session, or try to modify the configuration of the current session.
https://github.com/casbin/casbin/issues/1205 I used the registration of this business to achieve what the issue said. https://github.com/casbin/casbin/issues/1205#issuecomment-1501221142 use
db.Exec
it works But when I useddb.Model
ordb.Table
to set table name,it does not work,it executes table is casbin_rulewhat it actually does is
INSERT INTO casbin_rule (usernam,password) VALUES ('','')
I think db.Statement.scopes effect the table name, but I don't know how to resolve it