From f3bc7427bed391ab706f34d6aa639bcfd59ba51c Mon Sep 17 00:00:00 2001 From: wangjp01 Date: Mon, 11 Oct 2021 18:33:12 +0800 Subject: [PATCH] =?UTF-8?q?protocbuffer=20file:=20XXX=5FNoUnkeyedLiteral?= =?UTF-8?q?=20struct{}=20`json:"-"`=20db.Find(&Srt)=20raise=20error:=20=20?= =?UTF-8?q?=20=20=20=20field=20XXX=5FNoUnkeyedLiteral:=20define=20a=20vali?= =?UTF-8?q?d=20foreign=20key=20for=20relations=20or=20implement=20the=20Va?= =?UTF-8?q?luer/Scanner=20interface=20HOW=EF=BC=9Aadd=20filter:=20field.Ta?= =?UTF-8?q?g.Get("json")=20!=3D=20"-"=20WHY=EF=BC=9Aunsupported=20parsing?= =?UTF-8?q?=20type:=20struct{}=20=20=20=20set=20guessLevel=20to=20guessEmb?= =?UTF-8?q?eddedHas=20=20=20=20=20=20have=20been=20commented:schema/relati?= =?UTF-8?q?onship.go:381=20=20=20=20=20=20as=20follows=EF=BC=9A=20=20=20?= =?UTF-8?q?=20=20=20reguessOrErr=20:=3D=20func()=20{=20=20=20=20=20=20=09?= =?UTF-8?q?=09switch=20cgl=20{=20=20=20=20=20=20=09=09case=20guessGuess:?= =?UTF-8?q?=20=20=20=20=20=20=09=09=09schema.guessRelation(relation,=20fie?= =?UTF-8?q?ld,=20guessBelongs)=20=20=20=20=20=20=09=09case=20guessBelongs:?= =?UTF-8?q?=20=20=20=20=20=20=09=09=09schema.guessRelation(relation,=20fie?= =?UTF-8?q?ld,=20guessEmbeddedBelongs)=20=20=20=20=20=20=09=09case=20guess?= =?UTF-8?q?EmbeddedBelongs:=20=20=20=20=20=20=09=09=09schema.guessRelation?= =?UTF-8?q?(relation,=20field,=20guessHas)=20=20=20=20=20=20=09=09case=20g?= =?UTF-8?q?uessHas:=20=20=20=20=20=20=09=09=09schema.guessRelation(relatio?= =?UTF-8?q?n,=20field,=20guessEmbeddedHas)=20=20=20=20=20=20=09=09//=20cas?= =?UTF-8?q?e=20guessEmbeddedHas:=20=20=20=20=20=20=09=09default:=20=20=20?= =?UTF-8?q?=20=20=20=09=09=09schema.err=20=3D=20fmt.Errorf("invalid=20fiel?= =?UTF-8?q?d=20found=20for=20struct=20%v's=20field=20%s:=20define=20a=20va?= =?UTF-8?q?lid=20foreign=20key=20for=20relations=20or=20implement=20the=20?= =?UTF-8?q?Valuer/Scanner=20interface",=20schema,=20field.Name)=20=20=20?= =?UTF-8?q?=20=20=20=09=09}=20=20=20=20=20=20=09}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schema/relationship.go | 1 + schema/schema.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/schema/relationship.go b/schema/relationship.go index 5699ec5f..4fdc4c8e 100644 --- a/schema/relationship.go +++ b/schema/relationship.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/jinzhu/inflection" + "gorm.io/gorm/clause" ) diff --git a/schema/schema.go b/schema/schema.go index c425070b..b6d6a3bc 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -134,7 +134,7 @@ func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error) if fieldStruct := modelType.Field(i); ast.IsExported(fieldStruct.Name) { if field := schema.ParseField(fieldStruct); field.EmbeddedSchema != nil { schema.Fields = append(schema.Fields, field.EmbeddedSchema.Fields...) - } else { + } else if field.Tag.Get("json") != "-" { schema.Fields = append(schema.Fields, field) } }