{{# const table = Table.findOne({ name: query.table }) }}

The constraint formula should be a JavaScript expression which evaluates to a 
boolean (true or false). If the formula evaluates to false then the row is not
valid and will not be accepted in the table. If you are editing an existing row 
then the edit will not be accepted. The supplied error message text will be shown 
to the user. 

Some examples: 

{{# for (const fml of table.getFormulaExamples("Bool")) { }} * `{{ fml}}`
{{# } }}

This formula can use any of the fields in table {{ table.name }} as variables:

| Field | Variable name | Type |
| ----- | ------------- | ---- |
{{# for (const field of table.fields) { }} | {{ field.label }} | `{{ field.name }}` | {{ field.pretty_type }} | 
{{# } }}




{{# if(table.fields.some(f=>f.is_fkey)) { }}

You can also use join fields on related tables. These are accessed with the dot object access 
notation, in the form:

```
{key field}.{field on referenced table}
```

The first-order join fields you can use in the constraint formula are:

{{# for (const field of table.fields.filter(f=>f.is_fkey && f.reftable_name)) { }}
{{#  const reftable = Table.findOne( field.reftable_name); }}
* Through {{field.label}} key field: {{ reftable.fields.map(jf=>`\`${field.name}.${jf.name}\``).join(", ") }}


{{# } }}

If you use join fields, Saltcorn is not able to create a constraint in the SQL database. In that case, it will not check existing 
rows, and it will also not be able to enforce constraints involving the primary key value on newly created rows.

{{# } }}
