Skip to content

Conversation

clcy1243
Copy link

@clcy1243 clcy1243 commented Nov 2, 2023

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

fix bugs

  1. DO.UseDB will lost db.Statement.Context
  2. DO.ReplaceDB will lost table name
  3. DO.ReplaceDB will not clone db.Statement, so after Query.ReplaceDB, all Dao use same Statement

User Case Description

before fixed, u.Not(gen.Exists(student.Where(u.ID.EqCol(student.ID)))).Count() will return error after call q.ReplaceDB()

@clcy1243
Copy link
Author

clcy1243 commented Nov 3, 2023

@qqxhb please check this PR, thanks

func (d *DO) ReplaceDB(db *gorm.DB) {
d.db = db.Session(&gorm.Session{})
d.db = db.Session(&gorm.Session{Context: db.Statement.Context})
d.UseModel(reflect.New(d.modelType).Interface())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d.UseModel(d.newResultPointer())

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

Successfully merging this pull request may close these issues.

2 participants