many2many ondelete:CASCADE #1890
-
|
If I set type ModelA struct {
Id uint64 `pg:"id"`
ModelBs []*ModelB `pg:"many2many:modela_to_modelbs,on_delete:CASCADE"`
}
type ModelB struct {
Id uint64 `pg:"id"`
ModelAs []*ModelA `pg:"many2many:modela_to_modelbs,on_delete:CASCADE"`
}
type ModelAToModelB struct {
ModelAId uint64 `pg:"model_a_id,type:bigint"`
ModelBId uint64 `pg:"model_a_id,type:bigint"`
//nolint
tableName struct{} `pg:"modela_to_modelbs"`
}When I delete a ModelA, will all the ModelB's that are related to that ModelA also be deleted, or just the ModelAToModelB's? |
Beta Was this translation helpful? Give feedback.
Answered by
vmihailenco
Jun 16, 2021
Replies: 1 comment 2 replies
-
|
This is fixed in Bun by allowing to manually specify foreign keys - https://bun.uptrace.dev/guide/queries.html#creating-tables |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
vmihailenco
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
on_deleteonly works for has-one relation and it is only used when creating table schema withCreateTable. Specifically it addsFOREIGN_KEY some_id ON DELETE CASCADE- https://www.postgresql.org/docs/13/sql-createtable.htmlThis is fixed in Bun by allowing to manually specify foreign keys - https://bun.uptrace.dev/guide/queries.html#creating-tables