mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
doc: add information about the generated runtime package
This commit is contained in:
committed by
Ariel Mashraki
parent
6d34023cd9
commit
c5cef3cbd3
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user