From 8f37cb01959201e1b53460c6e0a0b00d9f64d0f1 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 1 Feb 2021 10:42:13 +0800 Subject: [PATCH] Make has to be a const, close #4024 --- schema/relationship.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/schema/relationship.go b/schema/relationship.go index 9b7d803c..0eaace89 100644 --- a/schema/relationship.go +++ b/schema/relationship.go @@ -18,6 +18,7 @@ const ( HasMany RelationshipType = "has_many" // HasManyRel has many relationship BelongsTo RelationshipType = "belongs_to" // BelongsToRel belongs to relationship Many2Many RelationshipType = "many_to_many" // Many2ManyRel many to many relationship + has RelationshipType = "has" ) type Relationships struct { @@ -88,7 +89,7 @@ func (schema *Schema) parseRelation(field *Field) *Relationship { } } - if relation.Type == "has" { + if relation.Type == has { // don't add relations to embeded schema, which might be shared if relation.FieldSchema != relation.Schema && relation.Polymorphic == nil && field.OwnerSchema == nil { relation.FieldSchema.Relationships.Relations["_"+relation.Schema.Name+"_"+relation.Name] = relation @@ -176,7 +177,7 @@ func (schema *Schema) buildPolymorphicRelation(relation *Relationship, field *Fi }) } - relation.Type = "has" + relation.Type = has } func (schema *Schema) buildMany2ManyRelation(relation *Relationship, field *Field, many2many string) { @@ -476,7 +477,7 @@ func (schema *Schema) guessRelation(relation *Relationship, field *Field, gl gue } if gl == guessHas || gl == guessEmbeddedHas { - relation.Type = "has" + relation.Type = has } else { relation.Type = BelongsTo }