a2.RemovePolicies() execute sql delete unexpected db's table : DELETE FROM casbin.casbin_rule2 WHERE ptype = 'p' and v0 = 't2' and v1 = 't2' and v2 = 't2' , it should be "casbin2.cabin_rule2".
We can also use .Clauses(dbresolver.Write) to manual connection switching before every db transaction like I do in pr https://github.com/casbin/gorm-adapter/pull/208#issuecomment-1505296620 ,but to reduce the scope of the impact of modifying the code, I update NewAdapterByMulDb to compatible transaction operation.
test code
a2.RemovePolicies()
execute sql delete unexpected db's table :DELETE FROM casbin.casbin_rule2 WHERE ptype = 'p' and v0 = 't2' and v1 = 't2' and v2 = 't2'
, it should be "casbin2.cabin_rule2".First the error appeared in this pr https://github.com/casbin/gorm-adapter/pull/208#issuecomment-1505296620 , and I use
DB.Clauses(dbresolver.Write)
fix itAfter I learn from gorm docs When using transaction, DBResolver will keep using the transaction and won’t switch to sources/replicas based on configuration
In this test, db transaction use "casbin" db ,because When using transaction, DBResolver will keep using the transaction and won’t switch to sources/replicas based on configuration, so db transaction use source "casbin" db to execute
RemovePolicies()
and it should be "casbin2" dbWe can also use
.Clauses(dbresolver.Write)
tomanual connection switching
before every db transaction like I do in pr https://github.com/casbin/gorm-adapter/pull/208#issuecomment-1505296620 ,but to reduce the scope of the impact of modifying the code, I update NewAdapterByMulDb to compatible transaction operation.