From 09114208bec0bfadd032b261639bf95294e762df Mon Sep 17 00:00:00 2001 From: Rotem Tamir Date: Tue, 11 Oct 2022 22:26:34 +0300 Subject: [PATCH] doc/website/blog: fixes to json append post (#3009) --- doc/website/blog/2022-10-10-json-append.mdx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/website/blog/2022-10-10-json-append.mdx b/doc/website/blog/2022-10-10-json-append.mdx index dcf692775b..d29e56411f 100644 --- a/doc/website/blog/2022-10-10-json-append.mdx +++ b/doc/website/blog/2022-10-10-json-append.mdx @@ -7,6 +7,7 @@ authorTwitter: _rtam image: "https://entgo.io/images/assets/ent-json-append.png" --- + import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; @@ -69,12 +70,14 @@ the desired field name as well as the backing Go type. For example: ```go type Tag struct { - Name string `json:"name"` + Name string `json:"name"` Created time.Time `json:"created"` } -func (User) BlogPost() []ent.Field { - field.JSON("tags", []Tag{}) +func (User) Fields() []ent.Field { + return []ent.Field{ + field.JSON("tags", []Tag{}), + } } ``` @@ -86,9 +89,9 @@ func TestEntJSON(t *testing.T) { ctx := context.Background() // Insert a user with two comments. client.User.Create(). - SetComments([]schema.Comment{ - {Title: "hello", Created: time.Now()}, - {Title: "goodbye", Created: time.Now()}, + SetTags([]schema.Tag{ + {Name: "hello", Created: time.Now()}, + {Name: "goodbye", Created: time.Now()}, }). SaveX(ctx)