> ## Documentation Index
> Fetch the complete documentation index at: https://docs.standardcomputers.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Standards as Constraints: Join and Traverse Related Records

> Create relationships between Standards by using another Standard as a constraint type, enabling you to traverse related records like database joins.

In traditional databases you perform joins or aggregations to combine related records. In the Standard System, you build relationships directly into your schema by declaring a constraint of type `standard`. When a record is saved, the constraint stores the record ID of the related Standard record — and from that point on you can traverse the relationship using the constraint name, its reference, or the parent Standard's reference.

## Defining a Standard Constraint

Use the `standard` type and prepend the target Standard's reference with `@` to declare a relationship:

```stds theme={null}
truck: TRCK: @VHL {
    protected owner standard @PER OWNR *
    protected max_weight double MXWGHT
}
```

Here, `owner` is a constraint that holds a reference to a `PER` (person) record. The constraint reference `OWNR` and the Standard reference `@PER` both give you ways to access the related record.

## Traversing Related Records

Once a `truck` record is saved, you can navigate to the linked `owner` record using the constraint name, the constraint reference, or the parent Standard's reference — all three are equivalent:

```stds theme={null}
#Get Trucks where vehicle make is 'Tesla', limit 1
foundTruck [TRCK] <VHL.MK "Tesla" LIMIT 1>

#Prints truck owner's first name
print foundTruck.OWNR.FNAME

#Also prints truck owner's first name
print foundTruck.owner.firstname

#again
print foundTruck.USR.firstname
```

<Info>
  When you access a Standard-type constraint, the system resolves the stored record ID and returns the full related record, making deeply nested traversals like `foundTruck.OWNR.FNAME` straightforward and readable.
</Info>

## Disambiguating Multiple Constraints of the Same Standard

If your Standard references the same parent Standard in more than one constraint, accessing the related record by the parent Standard's reference alone is ambiguous. In that case, the system always resolves to the **first** constraint that uses that Standard. To target a specific constraint, use the constraint name or its reference directly:

```stds theme={null}
truck: TRCK: @VHL {
    protected owner standard @PER OWNR *
    protected driver standard @PER DRVR *
}

#Init empty object
truck @TRCK

print truck PER firstname #Will only ever print the owner's firstname
print truck driver firstname #Now prints driver's firstname
```

<Warning>
  When two or more constraints share the same Standard type, always use the constraint name or constraint reference — not the Standard reference — to avoid accidentally reading from the wrong related record.
</Warning>
