Normalisation
normalizes declares a transform applied to an attribute before validation and
save, so the stored value is always canonical. Declare it in submethod BUILD.
1 2 3 4 5 6 7 8 | |
The normaliser runs before validation, so validations see the normalised value.
Multiple attributes
Pass several attribute names to apply the same normaliser to each:
1 | |
Queries
A lookup on a normalised attribute normalises the search value too, so a query matches what was stored regardless of the input's casing or whitespace:
1 | |
normalize-value-for(attribute, value) returns the normalised form of a value
(or the value unchanged when the attribute has no normaliser), which is what the
query layer uses.