mirror of
https://github.com/ent/ent.git
synced 2026-04-28 05:30:56 +03:00
entc: improve generated comments for edges and fields (#2632)
* replace default field comment with user comment if defined * use comments defined on edges in generated entities * add docs for comment method on edges and fields * update integration to reflect above changes
This commit is contained in:
@@ -24,6 +24,7 @@ type Descriptor struct {
|
||||
Required bool // required on creation.
|
||||
StorageKey *StorageKey // optional storage-key configuration.
|
||||
Annotations []schema.Annotation // edge annotations.
|
||||
Comment string // edge comment.
|
||||
}
|
||||
|
||||
// To defines an association edge between two vertices.
|
||||
@@ -98,7 +99,8 @@ func (b *assocBuilder) Through(name string, t interface{}) *assocBuilder {
|
||||
}
|
||||
|
||||
// Comment used to put annotations on the schema.
|
||||
func (b *assocBuilder) Comment(string) *assocBuilder {
|
||||
func (b *assocBuilder) Comment(c string) *assocBuilder {
|
||||
b.desc.Comment = c
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -165,7 +167,8 @@ func (b *inverseBuilder) StructTag(s string) *inverseBuilder {
|
||||
}
|
||||
|
||||
// Comment used to put annotations on the schema.
|
||||
func (b *inverseBuilder) Comment(string) *inverseBuilder {
|
||||
func (b *inverseBuilder) Comment(c string) *inverseBuilder {
|
||||
b.desc.Comment = c
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,10 @@ func TestEdge(t *testing.T) {
|
||||
type User struct{ ent.Schema }
|
||||
e := edge.To("friends", User.Type).
|
||||
Required().
|
||||
Comment("comment").
|
||||
Descriptor()
|
||||
assert.False(e.Inverse)
|
||||
assert.Equal("comment", e.Comment)
|
||||
assert.Equal("User", e.Type)
|
||||
assert.Equal("friends", e.Name)
|
||||
assert.True(e.Required)
|
||||
@@ -39,9 +41,11 @@ func TestEdge(t *testing.T) {
|
||||
e = edge.To("children", Node.Type).
|
||||
From("parent").
|
||||
Unique().
|
||||
Comment("comment").
|
||||
Field("parent_id").
|
||||
Descriptor()
|
||||
assert.Equal("parent_id", e.Field)
|
||||
assert.Equal("comment", e.Comment)
|
||||
assert.Empty(e.Ref.Field)
|
||||
|
||||
t.Log("m2m relation of the same type")
|
||||
|
||||
Reference in New Issue
Block a user