How to new a new db object from a db object ?
func QueryTest(db *gorm.DB) {
var res []User
db = db.Table("aaa").Where("aaa.id = 1")
db.Scopes(myScope).Find(&res)
}
func myScope(db *gorm.DB) *gorm.DB {
return db.Table("bbb").Where("bbb.id = 2")
}
In myScope, the db has a new condition where and table , but in QueryTest it has been set a table and where .
What will it happen ?
In myScope I want to new a new db and doesn't inhert the pervious db where and other condition .
It seems no New() function ?
func myScope(db *gorm.DB) *gorm.DB {
return db.New().Table("bbb").Where("bbb.id = 2")
}
In some complex subqueries I need to do something like this, new a db but doesn't inherit the condition .