mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31: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:
@@ -1416,6 +1416,23 @@ However, you should note, that this is currently an SQL-only feature.
|
||||
|
||||
Read more about this in the [Indexes](schema-indexes.md) section.
|
||||
|
||||
## Comments
|
||||
|
||||
A comment can be added to the edge using the `.Comment()` method. This comment
|
||||
appears before the edge in the generated entity code. Newlines are supported
|
||||
using the `\n` escape sequence.
|
||||
|
||||
```go
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("pets", Pet.Type).
|
||||
Comment("Pets that this user is responsible for taking care of.\n" +
|
||||
"May be zero to many, depending on the user.")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Annotations
|
||||
|
||||
`Annotations` is used to attach arbitrary metadata to the edge object in code generation.
|
||||
|
||||
@@ -508,6 +508,23 @@ func (User) Fields() []ent.Field {
|
||||
}
|
||||
```
|
||||
|
||||
## Comments
|
||||
|
||||
A comment can be added to a field using the `.Comment()` method. This comment
|
||||
appears before the field in the generated entity code. Newlines are supported
|
||||
using the `\n` escape sequence.
|
||||
|
||||
```go
|
||||
// Fields of the user.
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
Default("John Doe").
|
||||
Comment("Name of the user.\n If not specified, defaults to \"John Doe\"."),
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Storage Key
|
||||
|
||||
Custom storage name can be configured using the `StorageKey` method.
|
||||
|
||||
Reference in New Issue
Block a user