Sometimes you need to put a general constraint onto a column's value that requires conditional processing and specialized error messages. This can be done with a chain, using almost the same syntax as calculated values.
Consider the example of a shopping cart that offers some customers a steep discount. Others may qualify for free shipping. However, no customer can get both. Here is how to code this in Andromeda:
table orderlines:
module: ordering
description: Cart Items
column discount:
auto: fetch,customers.discount
column flag_freeship:
suffix: _freeship
chain cons:
test 00:
compare: @flag_freeship = N
return:
test 01:
compare: @discount <= 20
return:
test 02:
return: Discount exceeds 20%, free shipping not allowed
Now let us review the basic syntax of the 'chain'
Only one constraint chain is allowed per column. However, constraint chains have a peculiar property, they do not actually need to be defined on the column whose value you are testing -- they are really table-level definitions that we define for convenience on columns. Therefore, if required, you can put other constraints on other columns.
The syntax for the compare expressions is not very flexible, by the standards of most languages and by the rest of Andromeda. We hope to rectify this in a future release, but at least through Release 1 the following restrictions apply:
A list of supported comparison operators is available on the page on Calculated Values.
comments powered by Disqus