ErrorsEntities, stores and migrations · rule
data.unique_decimal_places
A unique rule covers a field kept as JSON that holds a percentage, or another value whose places its type doesn't fix, which its JSON can write two ways.
Area 5, Entities, stores and migrations; not declinable; the next step is usually the agent's.
Why Jadpo refuses it
A field whose type is an object, an enum with data, a list, a set or a
map is kept whole as its JSON, and a unique rule over it compares the
digest of that JSON. A percentage keeps its places in its JSON, so 12.5%
and 12.50% are == in code but written differently, as is any value
whose places its type doesn't fix. The rule would let both in, and two
records would hold what code calls the same value.
What it looks like
main.jadpo:
/// What a cup of coffee is made with.type Recipe = Object { milk: Percentage}entity Coffee { id: Uuid recipe: Recipe { unique: true }}
error Coffee.recipe can be written two ways, so no unique rule can compare it
--> main.jadpo:9:9
|9 | unique: true | ^^^^^^ kept as JSON
- reason
Coffee.recipeis kept as its JSON, and a unique rule compares the digest of that JSON; it holds aPercentage, whose JSON keeps its places, so12.5%and12.50%are==in code but written differently, and the rule would let both in.- next
- Hold a decimal whose type has a
scale:instead, or leave the field out of the unique rule (agent) - rule
- data.
unique_ decimal_ places - help
- https://jadpo.
dev/docs/errors/data. unique_ decimal_ places
(agent) at the end of the next: line means your coding agent can make
the fix itself.
How to fix it
If the share has a fixed number of places, keep it as a decimal
whose type has a scale:, so each value is written one way:
type MilkShare = Decimal { scale: 1 min: 0.0 max: 100.0}/// What a cup of coffee is made with.type Recipe = Object { milk: MilkShare}entity Coffee { id: Uuid recipe: Recipe { unique: true }}
No two coffees can now share a recipe.
If two records may share one, remove the rule:
/// What a cup of coffee is made with.type Recipe = Object { milk: Percentage}entity Coffee { id: Uuid recipe: Recipe}
Two coffees may now be made with the same recipe.
Related
Markdown for agents: /docs/errors/data.unique_decimal_places.md.Built from Jadpo's main branch at commit 9080dc3.