GORM Playground Link
Absolutely not.
Description
type ATable struct {
ID int32 `gorm:"->;primaryKey"`
Name string `gorm:"->"`
Related []*BTable `gorm:"many2many:atob"`
}
type BTable struct {
ID int32 `gorm:"primaryKey"`
Name string
Related []*ATable `gorm:"many2many:atob"`
}
Assume there are rows in ATable already. Any attemps to create a new BTable entry that has Related pointing to existing ATable entries will fail. This is because the ID field of ATable is marked "read-only" with "->". When gorm tries to insert into atob it only provides the BTable ID, leaving ATable ID to default to null.. which of course fails.
Removing the read-only mark fixes it, but I still don't want gorm modifying anything in the ATable.
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: AeronCyther
Facing the same issue when both table have their keys marked as readonly.
The generated query is
INSERT INTO "a_bs" DEFAULT VALUES ON CONFLICT DO NOTHING RETURNING "a_id","b_id"