ErrorsEntities, stores and migrations · rule
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; 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:
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 }}
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, withmin: 0, and amax:if it has a limit.Story.cheersisCheerCount. - next
- Type it as one built on
Intwithmin: 0(agent) - rule
- data.
total_ type - help
- https://jadpo.
dev/docs/errors/data. total_ type
(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:
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
Markdown for agents: /docs/errors/data.total_type.md.Built from Jadpo's main branch at commit 72d483f.