feat: delete constraint for belongs to and has one

This commit is contained in:
2025-03-18 03:29:00 +07:00
parent 4536be4d10
commit ffbeccc4fd
4 changed files with 10 additions and 4 deletions

View File

@@ -123,8 +123,14 @@ func CheckOneToMany(pass *analysis.Pass, models map[string]common.Model) {
if !foundOneToMany {
if foundBelongsTo {
fmt.Printf("`%s` belongs `%s`\n", *baseType, model.Name)
if CheckCascadeDelete(pass, field) {
return
}
} else if hasOne {
fmt.Printf("`%s` has one `%s` \n", model.Name, relatedModel.Name)
if CheckCascadeDelete(pass, field) {
return
}
} else {
pass.Reportf(field.Pos, "Invalid relation in field `%s`", field.Name)
}