# `data.stored_value_outside_update`

Stored field read outside an update by `id`.

Area 6, [Reads and writes](../topics/reads-and-writes.md); not declinable; the next step is usually the agent's.

`Counter.hits` is the value stored when an update by `id` runs, so only
that update reads it:

```jadpo
type Count = Int {
    min: 0
}

entity Counter {
    id: Uuid
    hits: Count
}

action hit(counter: Counter) -> Counter {
    return Counter.update(counter) {
        set: {
            hits: Count(Counter.hits + 1)
        }
    }
}
```

```text
error: `Counter.hits` is a stored value, read only by an update by `id`
 --> main.jadpo:13:25
   |
13 |             hits: Count(Counter.hits + 1)
   |                         ^^^^^^^^^^^^ stored value
  reason: `Counter.hits` is the value stored in the database when an update by `id` runs, which only that update's `set:` reads; elsewhere a record's field is read from the record loaded earlier.
  next: Read it from a loaded record, `counter.hits`, or use it in `Counter.update(counter_id) { set: { ... } }` (agent)
  rule: data.stored_value_outside_update
  help: https://jadpo.dev/docs/errors/data.stored_value_outside_update

check failed: 1 error, 1 file
```
