Your Question

How do you copy a DB? I tried doing the following:

q := db.Model(&Model{}).Select("*")
r := q.Session(&gorm.Session{})

However, whenever I change q by adding additional clauses, r gets modified as well. Is there a way to do what I wanted to do? Or is this by design?

The document you expected this should be explained

This should be explained in the Sessions page of the official documentation website.

Expected answer

I would like to know how to copy another DB object without having the original object affecting the copy.

Comment From: jinzhu

https://gorm.io/docs/method_chaining.html

Comment From: psahni

Hello I have same question this is not solved

Comment From: davidlbudiman

@psahni Jinzhu has posted the article to copy DB object without affecting the original object. Just read through it first.