From c5cef3cbd3a8d041166fba231400f879b2117924 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Fri, 12 Feb 2021 13:34:07 +0200 Subject: [PATCH] doc: add information about the generated runtime package --- doc/md/hooks.md | 12 ++++++++++-- doc/md/privacy.md | 5 +++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/md/hooks.md b/doc/md/hooks.md index 6aab97d73..bac9aa992 100755 --- a/doc/md/hooks.md +++ b/doc/md/hooks.md @@ -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 _ "/ent/runtime" diff --git a/doc/md/privacy.md b/doc/md/privacy.md index f31d44a0b..d9679ec52 100644 --- a/doc/md/privacy.md +++ b/doc/md/privacy.md @@ -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 _ "/ent/runtime"