# `data.total_type`

A total's type doesn't fit what it totals: a count is built on `Int` with `min: 0`, a sum on what it adds up, and either allows 0.

Area 5, [Entities, stores and migrations](/docs/data.md); not declinable; the next step is usually the agent's.

## Why Jadpo refuses it

A total holds what the records it counts add up to, so its type says
what that can be. A count is a whole number of records, never below
none, so its type is built on `Int` with `min: 0`. A sum holds what its
parts add up to, so its type is built on what it adds up: the same
`Int`, `Decimal` places or currency. A record with nothing counted holds
0, so either type allows 0, and is never `none`. A bound on a sum of
parts that may be above and below 0 is refused too, since removing a
record could then pass it, and a cascade, a purge or an erasure removes
records with nothing to refuse.

## What it looks like

main.jadpo:

```jadpo
type CheerCount = Int {}

entity Story {
    id: Uuid
    cheers: CheerCount {
        total: count(Cheer.story_id)
    }
}

entity Cheer {
    id: Uuid
    story_id: Story.id {
        on_delete: OnDelete.cascade
    }
}
```

```text
error: `Story.cheers` counts records, so its type is built on `Int` with `min: 0`
 --> main.jadpo:5:5
  |
5 |     cheers: CheerCount {
  |     ^^^^^^ not a count's type
  reason: A count is a whole number of records, never below none, so its type says so: built on `Int`, with `min: 0`, and a `max:` if it has a limit. `Story.cheers` is `CheerCount`.
  next: Type it as one built on `Int` with `min: 0` (agent)
  rule: data.total_type
  help: https://jadpo.dev/docs/errors/data.total_type

check failed: 1 error, 1 file
```

`(agent)` at the end of the `next:` line means your coding agent can make
the fix itself.

## How to fix it

**If the total counts records**, say that it is never below none, and
give it a `max:` if it has a limit. `main.jadpo` becomes:

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

entity Story {
    id: Uuid
    cheers: CheerCount {
        total: count(Cheer.story_id)
    }
}

entity Cheer {
    id: Uuid
    story_id: Story.id {
        on_delete: OnDelete.cascade
    }
}
```

`CheerCount` now holds any number of cheers from none up, as a count
does.

## Related

- [Totals the runtime keeps](/docs/fields-and-their-settings.md#totals-the-runtime-keeps)
- [`data.total_invalid`](/docs/errors/data.total_invalid.md)
