mirror of
https://github.com/ent/ent.git
synced 2026-04-28 05:30:56 +03:00
doc/edges: mention the edge-field option in examples
This commit is contained in:
committed by
Ariel Mashraki
parent
49d11cc774
commit
b444535a13
@@ -422,6 +422,28 @@ func Do(ctx context.Context, client *ent.Client) error {
|
||||
}
|
||||
```
|
||||
|
||||
Note that, the foreign-key column can be configured and exposed as an entity field using the
|
||||
[Edge Field](#edge-field) option as follows:
|
||||
|
||||
```go {4,14}
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("spouse_id").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("spouse", User.Type).
|
||||
Unique().
|
||||
Field("spouse_id"),
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examples/o2obidi).
|
||||
|
||||
## O2M Two Types
|
||||
@@ -503,6 +525,30 @@ func Do(ctx context.Context, client *ent.Client) error {
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
Note that, the foreign-key column can be configured and exposed as an entity field using the
|
||||
[Edge Field](#edge-field) option as follows:
|
||||
|
||||
```go {4,15}
|
||||
// Fields of the Pet.
|
||||
func (Pet) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("owner_id").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Pet.
|
||||
func (Pet) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("pets").
|
||||
Unique().
|
||||
Field("owner_id"),
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examples/o2m2types).
|
||||
|
||||
## O2M Same Type
|
||||
@@ -612,6 +658,29 @@ func Do(ctx context.Context, client *ent.Client) error {
|
||||
}
|
||||
```
|
||||
|
||||
Note that, the foreign-key column can be configured and exposed as an entity field using the
|
||||
[Edge Field](#edge-field) option as follows:
|
||||
|
||||
```go {4,15}
|
||||
// Fields of the Node.
|
||||
func (Node) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("parent_id").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Node.
|
||||
func (Node) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("children", Node.Type).
|
||||
From("parent").
|
||||
Unique().
|
||||
Field("parent_id"),
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examples/o2mrecur).
|
||||
|
||||
## M2M Two Types
|
||||
|
||||
@@ -819,4 +819,11 @@ html[data-theme='dark'] .header-slack-link:before {
|
||||
|
||||
html[data-theme='dark'] .navbar__logo {
|
||||
filter: invert(100%);
|
||||
}
|
||||
|
||||
.docusaurus-highlight-code-line {
|
||||
background-color: rgb(72, 77, 91);
|
||||
display: block;
|
||||
margin: 0 calc(-1 * var(--ifm-pre-padding));
|
||||
padding: 0 var(--ifm-pre-padding);
|
||||
}
|
||||
Reference in New Issue
Block a user