mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
doc: update documentation to include naming convention (#1144)
* Update documentation to include naming convention This change relates to my question in #1107 around naming convention for fields / edges. As a bonus, I added documentation around the StructTag method for edges, as seemed to be omitted. * s/camel/Pascal/g
This commit is contained in:
@@ -898,6 +898,23 @@ func (User) Edges() []ent.Edge {
|
||||
}
|
||||
```
|
||||
|
||||
## Struct Tags
|
||||
|
||||
Custom struct tags can be added to the generated entities using the `StructTag`
|
||||
method. Note that if this option was not provided, or provided and did not
|
||||
contain the `json` tag, the default `json` tag will be added with the field name.
|
||||
|
||||
```go
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("pets", Pet.Type).
|
||||
// Override the default json tag "pets" with "owner" for O2M relationship.
|
||||
StructTag(`json:"owner"`),
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Indexes
|
||||
|
||||
Indexes can be defined on multi fields and some types of edges as well.
|
||||
@@ -932,3 +949,8 @@ func (Pet) Edges() []ent.Edge {
|
||||
```
|
||||
|
||||
Read more about annotations and their usage in templates in the [template doc](templates.md#annotations).
|
||||
|
||||
## Naming Convention
|
||||
|
||||
By convention edge names should use `snake_case`. The corresponding struct fields generated by `ent` will follow the Go convention
|
||||
of using `PascalCase`. In cases where `PascalCase` is desired, you can do so with the `StorageKey` or `StructTag` methods.
|
||||
|
||||
@@ -554,3 +554,8 @@ func (User) Fields() []ent.Field {
|
||||
```
|
||||
|
||||
Read more about annotations and their usage in templates in the [template doc](templates.md#annotations).
|
||||
|
||||
## Naming Convention
|
||||
|
||||
By convention field names should use `snake_case`. The corresponding struct fields generated by `ent` will follow the Go convention
|
||||
of using `PascalCase`. In cases where `PascalCase` is desired, you can do so with the `StorageKey` or `StructTag` methods.
|
||||
|
||||
Reference in New Issue
Block a user