Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to new a new DB object from a DB #6489

Closed
cyxr001 opened this issue Jul 31, 2023 · 0 comments
Closed

How to new a new DB object from a DB #6489

cyxr001 opened this issue Jul 31, 2023 · 0 comments
Assignees
Labels
type:question general questions

Comments

@cyxr001
Copy link

cyxr001 commented Jul 31, 2023

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 .

@cyxr001 cyxr001 added the type:question general questions label Jul 31, 2023
@cyxr001 cyxr001 closed this as completed Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

2 participants