schema/edge: add support for configuring foreign-key symbols

Fixed #1423
This commit is contained in:
Ariel Mashraki
2021-04-04 14:42:21 +03:00
committed by Ariel Mashraki
parent 745afde770
commit f3f03e1edd
8 changed files with 79 additions and 14 deletions

View File

@@ -977,9 +977,20 @@ func (User) Edges() []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("cars", Car.Type).
// Set the symbol of the foreign-key constraint for O2M relationship.
StorageKey(edge.Symbol("cars_owner_id")),
edge.To("friends", User.Type).
// Set the join-table and the column names for M2M relationship.
// Set the join-table, and the column names for a M2M relationship.
StorageKey(edge.Table("friends"), edge.Columns("user_id", "friend_id")),
edge.To("groups", Group.Type).
// Set the join-table, its column names and the symbols
// of the foreign-key constraints for M2M relationship.
StorageKey(
edge.Table("groups"),
edge.Columns("user_id", "group_id"),
edge.Symbols("groups_id1", "groups_id2")
),
}
}
```