You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is unclear to me how, if at all, I can insert a new parent entity holding a nested many2many association while still being able to maintain a foreign key constraint on the association table, i.e.:
typeUserstruct {
Languages: []Language`gorm:"many2many:user_language"`
}
typeLanguagestruct {
Keystring
}
user:=User{
Languages: []Language{{Key: "nl-NL"}}
}
db.Save(&user) // Will fail on an fk constraint violation for user ID, as the user does not exist yet.
To be clear I understand I could Append the languages after first saving the user, but imo it would be desired behavior to be able to create a new entity with nested entities directly instead of having to append them separately after the Save.
Expected answer
How to achieve this if at all possible, and if not, would it be possible to open a feature request
The text was updated successfully, but these errors were encountered:
Document Link
Your Question
It is unclear to me how, if at all, I can insert a new parent entity holding a nested many2many association while still being able to maintain a foreign key constraint on the association table, i.e.:
To be clear I understand I could
Append
the languages after first saving the user, but imo it would be desired behavior to be able to create a new entity with nested entities directly instead of having to append them separately after theSave
.Expected answer
How to achieve this if at all possible, and if not, would it be possible to open a feature request
The text was updated successfully, but these errors were encountered: