VIA Clause - Relationship Path Traversal
The VIA clause in AXEL allows you to explicitly specify the relationship path when traversing between forms. This is essential when your relation field names don't match the target table name, or when you need to traverse multiple relationship hops.
Syntax
RELATED(Table[Column], VIA(field_name))
RELATED(Table[Column], VIA(field1, field2, field3, ...))
RELATEDTABLE(Table, VIA(field_name))
Why Use VIA?
In Mars, when you create a relation field, the field name might differ from the target form name. For example:
- A field named
assigned_customerlinks to theCustomersform - A field named
primary_locationlinks to theLocationsform
The VIA clause tells AXEL exactly which relation field to use for traversal.
Single-Hop Traversal
Basic Syntax
RELATED(TargetTable[column], VIA(relation_field))
Example: Get Customer Name for Orders
Data Model:
Orders (has field "customer" linking to Customers)
└── Customers (has field "name")
Query:
RELATED([Customers][name], VIA(customer))
What It Does:
- For each order record, AXEL looks at the
customerrelation field - Follows that relation to find the linked Customer record
- Returns the
namecolumn from that Customer
Example: Add Customer Info to Orders Table
ADDCOLUMNS(
[Orders],
"Customer Name", RELATED([Customers][name], VIA(customer)),
"Customer Email", RELATED([Customers][email], VIA(customer))
)
Result:
| Order ID | Amount | Customer Name | Customer Email |
|---|---|---|---|
| ORD001 | 150.00 | John Smith | john@email.com |
| ORD002 | 89.99 | Jane Doe | jane@email.com |
Multi-Hop Traversal
When you need to traverse multiple relationships in sequence, provide multiple field names separated by commas.
Basic Syntax
RELATED(Table[Column], VIA(field1, field2, field3))
How Multi-Hop Works
Each field in the VIA path is traversed sequentially:
Current Record
└── VIA(field1) ──> Intermediate Table 1
└── VIA(field2) ──> Target Table
Example: Get Region from Orders (2 Hops)
Data Model:
Orders (has field "customer")
└── Customers (has field "region")
└── Regions (has field "name")
Query:
RELATED([Regions][name], VIA(customer, region))
Example: Get Department from Orders (3 Hops)
ADDCOLUMNS(
[Orders],
"Department", RELATED([Departments][name], VIA(product, category, department))
)
Field Name Matching
AXEL performs intelligent field name matching:
- Exact match:
VIA(customer)→ looks forcustomer - Case-insensitive:
VIA(Customer)→ matchescustomer - With 's' suffix:
VIA(customer)→ matchescustomers
Using VIA with RELATEDTABLE
ADDCOLUMNS(
[Customers],
"Order Count", COUNTX(RELATEDTABLE([Orders], VIA(customer)), 1),
"Revenue", SUMX(RELATEDTABLE([Orders], VIA(customer)), [amount])
)
Orphan Records
When a relationship path is broken, the result is NULL by default. See JOIN and DEFAULT Options for handling orphans.
Next Steps
- VIA Advanced Examples - Real-world scenarios and best practices
- JOIN and DEFAULT Options
- RELATEDTABLE Function