Your Question

How to use the Association#Replace correctly?

I keep getting duplicated key not allowed error when I'm replacing a Many to Many with identical records:

Book { Authors: [1]}
Book.Association('Authors').Replace(Author{1})

and when I look into the implementation it seems to saveAssociation first before deleting, is it the reason of conflict?

I also tried .Clear() before .Replace() in a tx but didn't help

The document you expected this should be explained

https://gorm.io/docs/associations.html#Replacing-Associations

Expected answer

What's the way to use .Replace() correctly?