feat: one-to-many, belongs-to
This commit is contained in:
19
relationsCheck/checkBelongsTo.go
Normal file
19
relationsCheck/checkBelongsTo.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package relationsCheck
|
||||
|
||||
import (
|
||||
"gormlint/common"
|
||||
)
|
||||
|
||||
func IsBelongsTo(field common.Field, model common.Model, relatedModel common.Model) bool {
|
||||
foreignKey := field.Tags.GetParamOr("foreignKey", "Id")
|
||||
references := field.Tags.GetParamOr("references", relatedModel.Name+"Id")
|
||||
|
||||
if !model.HasField(references) {
|
||||
return false
|
||||
}
|
||||
if !relatedModel.HasField(foreignKey) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user