Skip to content

Replace in Many2Many #7557

@ibigbug

Description

@ibigbug

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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions