doc: add warning for Unwrap (#4217)

* entc: document Unwrap with panic, doc: add warning for Unwrap

* resolve feedback
This commit is contained in:
Chandler Davis
2024-09-19 17:43:13 -04:00
committed by GitHub
parent 009b396d7e
commit 0c74e8ee0d

View File

@@ -60,6 +60,11 @@ func rollback(tx *ent.Tx, err error) error {
You must call `Unwrap()` if you are querying edges off of a created entity after a successful transaction (example: `a8m.QueryGroups()`). Unwrap restores the state of the underlying client embedded within the entity to a non-transactable version.
:::warning Note
Calling `Unwrap()` on a non-transactional entity (i.e., after a transaction has been committed or rolled back) will
cause a panic.
:::
The full example exists in [GitHub](https://github.com/ent/ent/tree/master/examples/traversal).
## Transactional Client
@@ -176,4 +181,4 @@ Some drivers support tweaking a transaction's isolation level. For example, with
```go
tx, err := client.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelRepeatableRead})
```
```