Skip to content

Commit

Permalink
doc/website/blog: fixes to json append post (#3009)
Browse files Browse the repository at this point in the history
  • Loading branch information
rotemtam authored Oct 11, 2022
1 parent 96e1325 commit 0911420
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions doc/website/blog/2022-10-10-json-append.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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{}),
}
}
```

Expand All @@ -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)

Expand Down

0 comments on commit 0911420

Please sign in to comment.