Key

The key constraint restricts a value to one of the keys stored in a named index. These indexes are declared using vr_key, as described in Keys and References.

This constraint is primarily used to enforce referential integrity within a configuration document—for example, ensuring that a reference in one section corresponds to a defined identifier in another section.

Type Matrix

The following table summarizes how the key constraint applies to different node types.

Node Type

S

Value Type

Details

Integer

Text
ValueList[Text]

Constrains the integer value to reference a key from one of the specified indexes.

Boolean

Float

Text

Text
ValueList[Text]

Constrains the text value to reference a key from one of the specified indexes.

Date

Time

DateTime

Bytes

TimeDelta

RegEx

Value

ValueList

ValueMatrix

Section

SectionList

SectionWithTexts

NotValidated

Rules for Key

  1. Index Reference: The key constraint takes one or more text values. Each value names an index that the node value is allowed to reference.

    [app.start_filter]
    type: "text"
    key: "filter"
    
  2. Index Must Exist: Each referenced index must be defined elsewhere in the same Validation Rules document using vr_key.

    *[vr_key]*
    name: "filter"
    key: "filter.identifier"
    
    [filter]
    type: "SectionList"
    
    [filter.vr_entry.identifier]
    type: "text"
    
    [app.start_filter]
    type: "text"
    key: "filter"
    
  3. Multiple Indexes (OR Semantics): If multiple index names are specified, the value is valid if it exists in any of the listed indexes.

    [app.start]
    type: "text"
    key: "remote_action", "local_action"
    
  4. Type Alignment: The type of the referencing node must match the type of the keys stored in the referenced index.

    For example, an index built from text identifiers cannot be referenced by a node of type date.

    *[vr_key]*
    name: "filter"
    key: "filter.identifier"
    
    [filter]
    type: "SectionList"
    
    [filter.vr_entry.identifier]
    type: "text"
    
    [app.start_filter]
    type: "date"
    key: "filter"   # ERROR: Referenced keys are text, not date
    
  5. Case Sensitivity: Key comparisons are case-insensitive by default.

    If the The Case Sensitive Flag flag is set on the referencing node, the key match must be performed case-sensitively.

    *[filter]*
    identifier: "first"
    
    *[filter]*
    identifier: "second"
    
    [app]
    start_filter: "First"  # VALID: matches "first" (case-insensitive)
    

Example

In the following example, start_filter must reference one of the identifiers defined in the filter section list:

*[vr_key]*
name: "filter"
key: "filter.identifier"

[filter]
type: "SectionList"

[filter.vr_entry.identifier]
type: "text"

[app.start_filter]
type: "text"
key: "filter"
*[filter]*
identifier: "first"

*[filter]*
identifier: "second"

[app]
start_filter: "first"
*[filter]*
identifier: "first"

*[filter]*
identifier: "second"

[app]
start_filter: "third"  # ERROR: "third" is not defined