From c616f7f2e78b29e7e4da830d8db0e91f402d061a Mon Sep 17 00:00:00 2001 From: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Date: Tue, 16 Jun 2020 22:50:29 +0300 Subject: [PATCH] doc: add docs for edges storage-key option (#551) --- doc/md/schema-edges.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/md/schema-edges.md b/doc/md/schema-edges.md index 539c9b0ce..3924f0725 100755 --- a/doc/md/schema-edges.md +++ b/doc/md/schema-edges.md @@ -862,7 +862,6 @@ func Do(ctx context.Context, client *ent.Client) error { The full example exists in [GitHub](https://github.com/facebookincubator/ent/tree/master/examples/m2mbidi). - ## Required Edges can be defined as required in the entity creation using the `Required` method on the builder. @@ -881,6 +880,24 @@ func (Card) Edges() []ent.Edge { If the example above, a card entity cannot be created without its owner. +## StorageKey + +Custom storage configuration can be provided for edges using the `StorageKey` method. + +```go +// Edges of the User. +func (User) Edges() []ent.Edge { + return []ent.Edge{ + edge.To("pets", Pet.Type). + // Set the column name in the "pets" table for O2M relationship. + StorageKey(edge.Column("owner_id")), + edge.To("friends", User.Type). + // Set the join-table and the column names for M2M relationship. + StorageKey(edge.Table("friends"), edge.Columns("user_id", "friend_id")), + } +} +``` + ## Indexes Indexes can be defined on multi fields and some types of edges as well.