mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
schema/field: add annotations for overriding field struct-tags
This commit is contained in:
committed by
Ariel Mashraki
parent
f1a841d235
commit
ab9aa1fa45
@@ -20,13 +20,13 @@ import (
|
||||
type Card struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
ID int `json:"-"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// UpdateTime holds the value of the "update_time" field.
|
||||
UpdateTime time.Time `json:"update_time,omitempty"`
|
||||
// Number holds the value of the "number" field.
|
||||
Number string `json:"number,omitempty"`
|
||||
Number string `json:"-"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
|
||||
@@ -20,6 +20,10 @@ type Card struct {
|
||||
|
||||
func (Card) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
field.StructTag(
|
||||
"id", `json:"-"`,
|
||||
"number", `json:"-"`,
|
||||
),
|
||||
edge.StructTag(`json:"card_edges" mashraki:"edges"`),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ import (
|
||||
type Card struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID string `json:"id,omitempty"`
|
||||
ID string `json:"-"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// UpdateTime holds the value of the "update_time" field.
|
||||
UpdateTime time.Time `json:"update_time,omitempty"`
|
||||
// Number holds the value of the "number" field.
|
||||
Number string `json:"number,omitempty"`
|
||||
Number string `json:"-"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
|
||||
@@ -221,6 +221,12 @@ func Sanity(t *testing.T, client *ent.Client) {
|
||||
fi, ok := reflect.TypeOf(ent.Card{}).FieldByName("Edges")
|
||||
require.True(ok)
|
||||
require.NotEmpty(fi.Tag.Get("mashraki"))
|
||||
fi, ok = reflect.TypeOf(ent.Card{}).FieldByName("ID")
|
||||
require.True(ok)
|
||||
require.Equal("-", fi.Tag.Get("json"))
|
||||
fi, ok = reflect.TypeOf(ent.Card{}).FieldByName("Number")
|
||||
require.True(ok)
|
||||
require.Equal("-", fi.Tag.Get("json"))
|
||||
}
|
||||
|
||||
func Clone(t *testing.T, client *ent.Client) {
|
||||
|
||||
Reference in New Issue
Block a user