mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
doc: change assets path from s3 to entgo.io
This commit is contained in:
committed by
Ariel Mashraki
parent
361663954e
commit
b2f6834f67
@@ -10,7 +10,7 @@ are populated to the `Edges` field in the returned object.
|
||||
|
||||
Let's give an example hows does the API look like for the following schema:
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ and maintain applications with large data-models and sticks with the following p
|
||||
|
||||
<br/>
|
||||
|
||||

|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
@@ -239,7 +239,7 @@ func (Group) Fields() []ent.Field {
|
||||
Let's define our first relation. An edge from `User` to `Car` defining that a user
|
||||
can **have 1 or more** cars, but a car **has only one** owner (one-to-many relation).
|
||||
|
||||

|
||||

|
||||
|
||||
Let's add the `"cars"` edge to the `User` schema, and run `go generate ./ent`:
|
||||
|
||||
@@ -331,7 +331,7 @@ Assume we have a `Car` object and we want to get its owner; the user that this c
|
||||
For this, we have another type of edge called "inverse edge" that is defined using the `edge.From`
|
||||
function.
|
||||
|
||||

|
||||

|
||||
|
||||
The new edge created in the diagram above is translucent, to emphasize that we don't create another
|
||||
edge in the database. It's just a back-reference to the real edge (relation).
|
||||
@@ -392,7 +392,7 @@ func QueryCarUsers(ctx context.Context, a8m *ent.User) error {
|
||||
|
||||
We'll continue our example by creating a M2M (many-to-many) relationship between users and groups.
|
||||
|
||||

|
||||

|
||||
|
||||
As you can see, each group entity can **have many** users, and a user can **be connected to many** groups;
|
||||
a simple "many-to-many" relationship. In the above illustration, the `Group` schema is the owner
|
||||
@@ -449,7 +449,7 @@ go generate ./ent
|
||||
In order to run our first graph traversal, we need to generate some data (nodes and edges, or in other words,
|
||||
entities and relations). Let's create the following graph using the framework:
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
```go
|
||||
|
||||
@@ -5,7 +5,7 @@ title: Privacy
|
||||
|
||||
The `Policy` option in the schema allows configuring privacy policy for queries and mutations of entities in the database.
|
||||
|
||||

|
||||

|
||||
|
||||
The main advantage of the privacy layer is that, you write the privacy policy **once** (in the schema), and it is **always**
|
||||
evaluated. No matter where queries and mutations are performed in your codebase, it will always go through the privacy layer.
|
||||
@@ -24,12 +24,12 @@ in the same order they are declared in the schema.
|
||||
If all rules are evaluated without returning an error, the evaluation finishes successfully, and the executed operation
|
||||
gets access to the target nodes.
|
||||
|
||||

|
||||

|
||||
|
||||
However, if one of the evaluated rules returns an error or a `privacy.Deny` decision (see below), the executed operation
|
||||
returns an error, and it is cancelled.
|
||||
|
||||

|
||||

|
||||
|
||||
### Privacy Rules
|
||||
|
||||
@@ -55,7 +55,7 @@ There are three types of decision that can help you control the privacy rules ev
|
||||
|
||||
- `privacy.Skip` - Skip the current rule, and jump to the next privacy rule. This equivalent to returning a `nil` error.
|
||||
|
||||

|
||||

|
||||
|
||||
Now, that we’ve covered the basic terms, let’s start writing some code.
|
||||
|
||||
@@ -272,7 +272,7 @@ The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examp
|
||||
In this example, we're going to create a schema with 3 entity types - `Tenant`, `User` and `Group`.
|
||||
The helper packages `viewer` and `rule` (as mentioned above) also exist in this example to help us structure the application.
|
||||
|
||||

|
||||

|
||||
|
||||
Let's start building this application piece by piece. We begin by creating 3 different schemas (see the full code [here](https://github.com/ent/ent/tree/master/examples/privacytenant/ent/schema)),
|
||||
and since we want to share some logic between them, we create another [mixed-in schema](schema-mixin.md) and add it to all other schemas as follows:
|
||||
|
||||
@@ -8,7 +8,7 @@ title: Edges
|
||||
Edges are the relations (or associations) of entities. For example, user's pets, or group's users.
|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
In the example above, you can see 2 relations declared using edges. Let's go over them.
|
||||
|
||||
@@ -177,7 +177,7 @@ Let's go over a few examples that show how to define different relation types us
|
||||
|
||||
## O2O Two Types
|
||||
|
||||

|
||||

|
||||
|
||||
In this example, a user **has only one** credit-card, and a card **has only one** owner.
|
||||
|
||||
@@ -256,7 +256,7 @@ The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examp
|
||||
|
||||
## O2O Same Type
|
||||
|
||||

|
||||

|
||||
|
||||
In this linked-list example, we have a **recursive relation** named `next`/`prev`. Each node in the list can
|
||||
**have only one** `next` node. If a node A points (using `next`) to node B, B can get its pointer using `prev` (the back-reference edge).
|
||||
@@ -352,7 +352,7 @@ The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examp
|
||||
|
||||
## O2O Bidirectional
|
||||
|
||||

|
||||

|
||||
|
||||
In this user-spouse example, we have a **symmetric O2O relation** named `spouse`. Each user can **have only one** spouse.
|
||||
If user A sets its spouse (using `spouse`) to B, B can get its spouse using the `spouse` edge.
|
||||
@@ -426,7 +426,7 @@ The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examp
|
||||
|
||||
## O2M Two Types
|
||||
|
||||

|
||||

|
||||
|
||||
In this user-pets example, we have a O2M relation between user and its pets.
|
||||
Each user **has many** pets, and a pet **has one** owner.
|
||||
@@ -507,7 +507,7 @@ The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examp
|
||||
|
||||
## O2M Same Type
|
||||
|
||||

|
||||

|
||||
|
||||
In this example, we have a recursive O2M relation between tree's nodes and their children (or their parent).
|
||||
Each node in the tree **has many** children, and **has one** parent. If node A adds B to its children,
|
||||
@@ -616,7 +616,7 @@ The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examp
|
||||
|
||||
## M2M Two Types
|
||||
|
||||

|
||||

|
||||
|
||||
In this groups-users example, we have a M2M relation between groups and their users.
|
||||
Each group **has many** users, and each user can be joined to **many** groups.
|
||||
@@ -708,7 +708,7 @@ The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examp
|
||||
|
||||
## M2M Same Type
|
||||
|
||||

|
||||

|
||||
|
||||
In this following-followers example, we have a M2M relation between users to their followers. Each user
|
||||
can follow **many** users, and can have **many** followers.
|
||||
@@ -802,7 +802,7 @@ The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examp
|
||||
|
||||
## M2M Bidirectional
|
||||
|
||||

|
||||

|
||||
|
||||
In this user-friends example, we have a **symmetric M2M relation** named `friends`.
|
||||
Each user can **have many** friends. If user A becomes a friend of B, B is also a friend of A.
|
||||
|
||||
@@ -8,7 +8,7 @@ title: Fields
|
||||
Fields (or properties) in the schema are the attributes of the node. For example, a `User`
|
||||
with 4 fields: `age`, `name`, `username` and `created_at`:
|
||||
|
||||

|
||||

|
||||
|
||||
Fields are returned from the schema using the `Fields` method. For example:
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func (User) Fields() []ent.Field {
|
||||
Indexes can be configured on composition of fields and edges. The main use-case
|
||||
is setting uniqueness on fields under a specific relation. Let's take an example:
|
||||
|
||||

|
||||

|
||||
|
||||
In the example above, we have a `City` with many `Street`s, and we want to set the
|
||||
street name to be unique under each city.
|
||||
|
||||
@@ -6,7 +6,7 @@ title: Graph Traversal
|
||||
For the purpose of the example, we'll generate the following graph:
|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
The first step is to generate the 3 schemas: `Pet`, `User`, `Group`.
|
||||
|
||||
@@ -157,7 +157,7 @@ func Gen(ctx context.Context, client *ent.Client) error {
|
||||
|
||||
Let's go over a few traversals, and show the code for them:
|
||||
|
||||

|
||||

|
||||
|
||||
The traversal above starts from a `Group` entity, continues to its `admin` (edge),
|
||||
continues to its `friends` (edge), gets their `pets` (edge), gets each pet's `friends` (edge),
|
||||
@@ -186,7 +186,7 @@ func Traverse(ctx context.Context, client *ent.Client) error {
|
||||
|
||||
What about the following traversal?
|
||||
|
||||

|
||||

|
||||
|
||||
We want to get all pets (entities) that have an `owner` (`edge`) that is a `friend`
|
||||
(edge) of some group `admin` (edge).
|
||||
|
||||
@@ -74,7 +74,7 @@ class HomeSplash extends React.Component {
|
||||
const ProjectTitle = () => (
|
||||
<div>
|
||||
<div className="projectTitleContainer">
|
||||
<img src="https://s3.eu-central-1.amazonaws.com/entgo.io/assets/logo.png" />
|
||||
<img src="https://entgo.io/assets/logo.png" />
|
||||
<div className="projectTitle">
|
||||
<p>{siteConfig.tagline}</p>
|
||||
</div>
|
||||
@@ -115,7 +115,7 @@ class HomeSplash extends React.Component {
|
||||
</a>
|
||||
</div>
|
||||
<div className="gopherGraph">
|
||||
<img src="https://s3.eu-central-1.amazonaws.com/entgo.io/assets/gopher_graph.png" />
|
||||
<img src="https://entgo.io/assets/gopher_graph.png" />
|
||||
</div>
|
||||
<Features />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user