doc: add information about the generated runtime package

This commit is contained in:
Ariel Mashraki
2021-02-12 13:34:07 +02:00
committed by Ariel Mashraki
parent 6d34023cd9
commit c5cef3cbd3
2 changed files with 13 additions and 4 deletions

View File

@@ -191,8 +191,16 @@ func (Card) Hooks() []ent.Hook {
}
}
```
> **Note that** if you use **schema hooks**, you **MUST** add the following import in the
> main package, because a circular import is possible.
## Hooks Registration
When using [**schema hooks**](#schema-hooks), there's a chance of a cyclic import between the schema package,
and the generated ent package. To avoid this scenario, ent generates an `ent/runtime` package which is responsible
for registering the schema-hooks at runtime.
> Users **MUST** import the `ent/runtime` in order to register the schema hooks.
> The package can be imported in the `main` package (close to where the database driver is imported),
> or in the package that creates the `ent.Client`.
>
> ```go
> import _ "<project>/ent/runtime"

View File

@@ -107,8 +107,9 @@ func main() {
}
```
> You should notice that, similar to schema hooks, if you use the **`Policy`** option in your schema,
> you **MUST** add the following import in the main package, because a circular import is possible:
> You should notice that, similar to [schema hooks](hooks.md#hooks-registration), if you use the **`Policy`** option in your schema,
> you **MUST** add the following import in the main package, because a circular import is possible between the schema package,
> and the generated ent package:
>
> ```go
> import _ "<project>/ent/runtime"