ent: initial support for edge schemas #2560
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Edge Schema
The
Through
option allows setting intermediate entity schemas for edges of type M2M. We name such schemas "edge schemas".Using this option, users can expose relationships in their API, store additional fields on their edges/relationships,
apply CRUD operations, and set hooks and privacy policy on them.
User Friendships Example
In the following example, we demonstrate how to model the friendship between two users using edge schema with the two
required fields of the relationship (
user_id
andfriend_id
) and an additional field namedcreated_at
that its valueis automatically set on creation.
Notes
ID
field is automatically generated for edge schemas if not stated otherwise.user_id
andfriend_id
edge-fields are required in the edge schema as they are composing the relationship.:::User Likes Example
In the following example, we demonstrate how to model a system where users can "like" tweets, and the timestamp of when
exactly the "like" has happened is stored in the database. i.e. store additional fields on the edge.
Notes
Since the
field.ID
annotation is used for configuring a composite identifier (i.e. primary key) for the edge schema,the
ID
field will not be generated along with any of its builder methods. e.g.Get
,OnlyID
, etc.