Skip to content

Commit 8f37cb0

Browse files
committed
Make has to be a const, close #4024
1 parent db0cc4d commit 8f37cb0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

schema/relationship.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
HasMany RelationshipType = "has_many" // HasManyRel has many relationship
1919
BelongsTo RelationshipType = "belongs_to" // BelongsToRel belongs to relationship
2020
Many2Many RelationshipType = "many_to_many" // Many2ManyRel many to many relationship
21+
has RelationshipType = "has"
2122
)
2223

2324
type Relationships struct {
@@ -88,7 +89,7 @@ func (schema *Schema) parseRelation(field *Field) *Relationship {
8889
}
8990
}
9091

91-
if relation.Type == "has" {
92+
if relation.Type == has {
9293
// don't add relations to embeded schema, which might be shared
9394
if relation.FieldSchema != relation.Schema && relation.Polymorphic == nil && field.OwnerSchema == nil {
9495
relation.FieldSchema.Relationships.Relations["_"+relation.Schema.Name+"_"+relation.Name] = relation
@@ -176,7 +177,7 @@ func (schema *Schema) buildPolymorphicRelation(relation *Relationship, field *Fi
176177
})
177178
}
178179

179-
relation.Type = "has"
180+
relation.Type = has
180181
}
181182

182183
func (schema *Schema) buildMany2ManyRelation(relation *Relationship, field *Field, many2many string) {
@@ -476,7 +477,7 @@ func (schema *Schema) guessRelation(relation *Relationship, field *Field, gl gue
476477
}
477478

478479
if gl == guessHas || gl == guessEmbeddedHas {
479-
relation.Type = "has"
480+
relation.Type = has
480481
} else {
481482
relation.Type = BelongsTo
482483
}

0 commit comments

Comments
 (0)