ADL 0.6.0 reference · Review draft 1 · November 14, 2026.
Contents · Source map · Evidence
The 0.6 edition note
This chapter retains the detailed language contract and its source-specific observations. Its chapter number and numbered sections remain stable. The 0.6 additions do not by themselves change this subject’s defaults or supply fresh execution evidence for it.
Reverification should cover foreign-key authority, relationship subroutes, and cross-domain resolution. Use the original examples and evidence links below to recover the earlier test context. The new edition’s source map records this chapter as inherited detail; the current draft does not claim those historical tests were rerun.
Retained reference detail
The numbered sections below are carried from 12-relationships-and-cross-domain-references.md. Their original baseline and evidence remain attached to the source. Statements about “current” or “checked” behavior in this retained text refer to those original observations unless the edition note explicitly updates them. This is a consolidated draft, not a claim of complete re-verification.
12.1 Scope and authority
A relationship describes how resources are connected and which side owns the
key. A reference field holds the canonical address of a record. Both can name
another resource, but the declaration, wire value, physical binding, and
available integrity guarantees must be distinguished.
The inherited body is v0.5.0 Chapter 12 (retired), converted from v0.3.1 Chapter 8. Its §§12.1–12.6 retain their subject ownership here. Draft 05 §10 adds cross-domain relationships, reference fields, and authority; §§11–12 govern the migration and naming consequences. The signed Spec-04 rulings R0-b and R4 narrow physical renaming and define the owner-chain and remote include boundaries. Their signed entries are preserved in the decision log.
ADL 7 owns address grammar and reference literals; ADL 10 owns field types and nullability; ADL 13 owns composition; ADL 14 owns mapping; ADL 15 owns indexes; ADL 17 owns migration declarations; and ADL 21 owns permissions. Generated routes, query parameters, errors, OpenAPI, and operation catalogs belong to ADL 26, 27, 31, 32, and 33.
12.2 Declare a relationship and locate its key
Declare relationships in a resource’s relationships mapping. Each key is a
relationship name and each value is a mapping. Names and local resource
targets are case-sensitive. Use the four exact type spellings below.
| Type | Key ownership | Result cardinality |
|---|---|---|
belongsTo | This resource holds a foreign key to target | One target, or no target when optional |
hasOne | target holds the foreign key back to this resource | At most one related row |
hasMany | target holds the foreign key back to this resource | Zero or more related rows |
belongsToMany | A junction table holds keys to both resources | Zero or more related rows |
hasOne and hasMany are inverse views of a key on the target. Declaring
either does not move that key to the resource containing the relationship.
Declare the target-side field and its owning belongsTo relationship when
the model requires a physical foreign-key constraint. For hasOne, make that
field unique when the storage model must enforce one-to-one cardinality; the
checked generator does not add uniqueness merely because hasOne is present.
| Property | Value type | Applies to | Required or default |
|---|---|---|---|
type | string | All | Required; one of the four types above |
target | string | All | Required |
foreignKey | string | All | Derived for belongsTo and belongsToMany; required for hasOne/hasMany |
onDelete | string | belongsTo | none for the inherited local contract |
cascade | string | belongsTo | Compatibility alias for onDelete |
required | boolean | belongsTo | false |
orderBy | mapping | hasMany | {} |
where | mapping | hasMany | {} |
through | string | belongsToMany | Derived junction name |
otherKey | string | belongsToMany | Derived target key name |
timestamps | boolean | belongsToMany | false |
When both delete keys occur, onDelete wins and cascade is ignored without
a diagnostic. AVOID cascade as a property spelling; cascade: restrict
is legal compatibility syntax but obscures the policy being declared.
A parser MUST diagnose a non-mapping relationship, a missing or unknown
type, a missing target, a property of the wrong value type, and an unknown
property. An unknown relationship type MUST NOT silently become a default.
The checked strict parser rejects hasLots; the CLI’s checked validation
path warns and exits successfully. That warning does not make the type valid.
12.3 Declared values, effective values, and columns
An omitted derivable value acquires an effective value without changing the source document. Derivations MUST be deterministic. A parser MUST preserve the declared relationship name and expose both declared and effective values.
| Declaration | Effective value when omitted |
|---|---|
belongsTo.foreignKey | Relationship name followed by Id |
belongsToMany.through | The two resource names sorted lexically and concatenated |
belongsToMany.foreignKey | This resource name with its first character lowercased, followed by Id |
belongsToMany.otherKey | Target resource name with its first character lowercased, followed by Id |
For Book.author, the foreign key is authorId. For Book.tags targeting
Tag, the logical junction name is BookTag, with bookId and tagId.
hasOne and hasMany require an explicit foreignKey naming the field on
their target; authors must not rely on the checked resolver’s extra fallback
to a name derived from the owning resource.
A belongsTo foreign-key column MUST exist. If its field is absent from
object, the column is generated with the target primary key’s type. An
integer target therefore needs an integer foreign key. The generated column
does not add an authored field to the resolved source document. If a field is
declared explicitly, its storage type must be compatible with the target key.
Observed representation. In the checked library, parsing retains an empty
foreignKey for the omitted Book.author key. The subsequent relationship
resolver fills authorId. Its resolved model stores the junction’s physical
name, library_book_tags, while the logical derivation above is BookTag.
An explicit through: BookLabels is also passed through physical naming.
Do not copy a deployment’s prefixed table name into source as though it were
the language’s logical derivation. The
generated catalog
retains source trees, model projections, and SQL separately.
12.4 Deletion policies
The inherited local belongsTo contract has five canonical, case-sensitive
values. The default is none. Cross-domain authority further constrains
physical foreign keys under §12.9.
onDelete | Meaning when the target is deleted |
|---|---|
cascade | Delete referencing rows |
restrict | Refuse deletion while references remain |
nullify | Clear the foreign key |
anonymise | Apply the referencing rows’ anonymisation policy |
none | Perform no ADL delete transformation |
For restrict, the delete action counts the referencing rows before it
deletes. While any remain, it refuses with 409 DELETE_RESTRICTED and leaves
the row in place. The message and data name the relationship (the target’s
hasMany/hasOne name when one is declared, otherwise the belongsTo
name), the referencing resource, the foreign key and the count:
{"relationship": "books", "resource": "Book", "foreignKey": "authorId", "count": 2}. The answer is the same on SQLite and PostgreSQL (#1482).
A soft delete (features.softDelete) is refused the same way (#1489). It keeps
the row, so the database’s foreign key never objects, but the parent would
then answer 404 while its children still point at it. When the referencing
resource also soft-deletes, only its active rows block a soft delete;
rows that are themselves soft-deleted do not. A hard delete counts those
tombstones too, because their rows still reference the parent. The check
covers local, single-column relationships. A composite or cross-domain
restrict is still refused by the database’s foreign key.
none does not authorize a dangling physical foreign key. A database can
still refuse deletion because its foreign-key constraint remains in force.
The checked SQLite DDL omits the ON DELETE clause for none, and a populated
reference causes the delete action to return 422 FOREIGN_KEY_VIOLATION.
Six compatibility spellings are accepted: delete → cascade; null and
set null → nullify; anonymize → anonymise; noaction and no action →
none. AVOID these spellings. CASCADE is not the canonical value
cascade, even though the checked production parser accepts it. The Python
modeller rejects it as UNKNOWN_ON_DELETE.
An unrecognized value MUST be an error naming that value, never an implicit
none. nullify is invalid when the effective foreign key is required.
The checked generator rejects both nullify and anonymise against the
example’s required authorId, after parsing and relationship resolution have
succeeded. Its nullable anonymise SQL uses RESTRICT; this alone does not
prove that privacy processing runs. ADL 45
owns anonymisation and erasure operations.
The populated SQLite probes demonstrate cascade deletion and nullification.
The full four-kind example’s restricted delete fails with 500 DB_ERROR;
the simpler none case returns the specific foreign-key error above. These
different error envelopes are observations to reconcile, not two prescribed
contracts. Junction cleanup uses ON DELETE CASCADE on both junction keys in
the checked generator, separately from the owning resource’s local policy.
12.5 Validation and failure boundaries
After resources and fields are known, the inherited static requirements are:
- A local
targetnames a resource in the domain. PlatformUserMAY be referenced without a local declaration; a localUsertakes precedence. - A
belongsToeffective foreign key is declared or generated under §12.3. - A
hasOne/hasManyforeign key names a field on its target. - A
belongsToManyhas non-empty effectivethrough,foreignKey, andotherKeyvalues. orderByandwhereare mappings;requiredandtimestampsare booleans.- A self-reference is valid and obeys the same rules.
Draft 05 extends target resolution across domains; a remote reference field does not acquire a local FK merely because its address is syntactically valid.
Observed boundaries in the recorded artifacts:
| Input | Observed result |
|---|---|
Missing type/target; scalar relationship | Parser rejection |
| Unknown type in strict parse | Rejection naming the relationship and legal values |
| Unknown type in non-strict parse/CLI | Warning, modeled as belongsTo |
| Unknown relationship property | Production warning; no modeller diagnostic in the selected case |
| Unknown or wrong-case local target | Parse succeeds; relationship resolution fails |
Canonical adl.library.library.Author put in target | Legacy resolver looks for domain adl; resolution fails |
Integer foreignKey or onDelete value | Accepted without the required type diagnostic; value ignored |
| Missing inverse foreign key or nonexistent inverse field | Production parse/resolution/DDL succeed; modeller rejects missing hasMany key only |
Non-mapping where/orderBy | Accepted and ignored by production parser |
String required/timestamps | Generic JSON type exception captured by the adapter |
Required FK with nullify | Production DDL rejection; modeller NULLIFY_REQUIRES_NULLABLE |
Integer FK targeting platform User | Resolves to authd_users.id, then DDL rejects the INTEGER/TEXT mismatch |
The inherited error record’s blanket silent-unknown-type statement is therefore outdated for strict parsing. It remains relevant to the non-strict fallback. Neither successful parse nor successful DDL generation establishes that all static obligations were checked. Exact diagnostic envelopes belong to ADL 31.
12.6 Composite primary keys
A resource MAY use more than one field as its primary key. This is a fragment from the complete enrollment example:
compositePrimaryKey: [studentId, courseId]
The value MUST be a non-empty list of distinct names. Every named field MUST
exist in object and be required: true. The resource MUST NOT also declare
an individual field with primaryKey: true. The declared order MUST be
preserved: (studentId, courseId) and (courseId, studentId) give different
index prefixes.
The checked baseline DDL preserves that order, and the reordered variant reverses it. Empty, duplicate, missing-field, optional-field, and conflicting single-key variants all pass the checked production parse and DDL-generation path. SQL generation is not database execution or evidence that these invalid declarations conform.
The foreignKey and otherKey properties in §12.2 are scalar names. This
composite identity rule does not define a list-valued foreign-key syntax or
prove that every generated relationship route supports composite identities.
The adapter does not exercise CRUD or remote literals for composite keys.
Canonical reference literals still carry a UUID under ADL 7.
12.7 Reference fields and the locality boundary
Declare a record-valued address with type: reference and references
naming a resource address of arity four. This field fragment comes from
the complete clinical domain:
person:
type: reference
references: "adl.health.party.Person"
The logical and wire value is the canonical reference string everywhere:
adl.health.party.Person:11111111-1111-4111-8111-111111111aaa.
It is neither a bare UUID nor an embedded Person object. ADL 7 owns address
segments, pins, case, and UUID normalization; ADL 10 owns reference type
validation. A field’s references address describes the expected target.
Draft 05 §10.1 requires domains in the same site to share a database and permits real cross-domain foreign keys, joins, cascades, and a shared transaction there. Across sites, references have no FK constraint, join, cascade, or shared transaction.
| Concern | Co-located target | Remote target |
|---|---|---|
| Author declaration | type: reference plus resource address | Same declaration form |
| Read/write wire value | Canonical address:uuid string | Canonical address:uuid string |
| Physical representation | MAY use UUID FK plus binding metadata | Store the complete reference string |
| Integrity | Inspect the chosen binding and its actual constraints | No cross-site FK integrity |
| Include | Depends on an implemented local binding | Must return the string; no remote fetch |
The checked implementation stores all reference fields as TEXT, including
the co-located suite example, and creates no FK for them. A validly shaped
reference naming adl.remote.other.Person is accepted into the field declared
for adl.health.party.Person. The expected target is not enforced on that
write path. A direct SQL deletion of the co-located target leaves the original
reference readable. These are limitations; absence of an FK is not
RESTRICT enforcement.
The suite probe confirms lowercase UUID-tail output and string /
adl-reference OpenAPI field format. It does not prove address lookup, remote
record existence, authorization, or transport-level access.
12.8 Physical bindings, names, and evolution
The resolver chooses locality at load time. Draft 05 §10.2 requires the resolved artifact to record the chosen physical binding so a deployment’s integrity is inspectable. A resource export identifying a table is useful, but does not by itself describe each reference field’s binding or prove an FK exists.
Draft 05 §12 specifies PostgreSQL schema {domain}_v{major} with resource
tables, and SQLite tables {domain}_v{major}_{resource}. Signed R0-b applies
that naming to domains first activated under 0.5.1. Existing tables are
grandfathered, consumers resolve actual names through export facts, and
0.5.1-a requires no rename migration of those existing tables.
Observed gap. The fresh suite store reports party_people and
clinical_profiles, with binding: table and pk_column: id in
adl_exports. The reference field in the schema action retains type and
references, but no selected per-field binding. The Phase-12 delivery already
flags the new-name switch as incomplete. Grandfathering cannot explain old
names in this fresh store, and the governing R0-b rule remains unchanged.
The checked foreign-mapping example also exports bridge_people while its
actual table is legacy_people; do not treat every exported name as verified
physical truth.
Changing a binding from co-located to remote, or back, is a site migration. The migration MUST translate storage without changing the logical reference value and MUST fail before applying if a UUID cannot be expanded to its canonical address or a remote reference cannot be reduced to the expected local target. No such migration is executed by this chapter’s probes.
ADL 5 owns suite dependency processing;
ADL 6 owns major-version
identity; ADL 17 owns dependency-closure activation, transaction boundaries,
referenced-column renames, and DOMAIN_REMOVAL_BLOCKED. The platform companion
owns storage configuration and migration execution. The naming formula does
not reinstate the retired promise of runtime major-version coexistence.
12.9 Cascade and write authority across domains
Cross-domain physical foreign keys are RESTRICT by default under Draft 05
§10.3. A cascading declaration needs the target resource’s opt-in. The
target also controls which importing domains may create or modify its rows
under §10.4. Both keys belong beside object, on the target resource.
This is a resource fragment from the party example:
allowCascadeFrom: [clinical]
allowWriteFrom: [registration]
These are lists of domain names. In allowWriteFrom the entry "*" stands for
every domain of the resource’s own suite, so a shared domain can accept writes
from whichever domains a suite deploys beside it without naming them.
allowCascadeFrom supplies cascade authority;
allowWriteFrom supplies write authority. The default for imported writes is
read-only. Read permission or a caller’s ability to name a resource is not
itself an importing domain’s write grant. Bedrock domains are soft-delete-only
under §10.3; the example explicitly enables features.softDelete. This chapter
does not establish an automatic classifier or enforcement mechanism for every
bedrock deployment.
Observed enforcement gap. Both grant lists are retained by the parser,
but the inspected sources contain no consumer of those vectors that checks a
calling domain. A legacy local-store relationship from orders.Purchase to
catalog.Product, using target: catalog.Product and onDelete: cascade,
deletes referencing purchases whether or not the target declares
allowCascadeFrom: [orders]. Both populated sequences succeed. This is a
counterexample to relying on the grant for cascade protection in the recorded
build. Legacy domain.Resource target syntax is not the canonical arity-four
references address grammar.
Where the write grant is enforced. A schedule’s create and a workflow’s
create step that name another domain’s resource consult allowWriteFrom
before writing and are refused with WRITE_AUTHORITY_DENIED without it
(ADL 36 §36.5.2, ADL 37). This settles the bedrock fixture’s finding F3 for
those two paths: an automation runs as the system, and the grant still
applies. An HTTP caller writing to a resource through its own routes is
governed by that resource’s permissions, not by this grant.
The checked mapping: foreign guard rejects create, update, and delete with
403 WRITE_AUTHORITY_DENIED, both with and without allowWriteFrom. That
blanket foreign-table guard is real protection, but it does not demonstrate
the specified per-domain grant mechanism. The synthetic admin used by these
probes supplies no importing-domain delegation context. ADL 14 and ADL 21
must reconcile mapping and permission behavior before publication.
12.10 Expansion and owner chains
A local relationship include expands the named relationship, subject to its
cardinality. In the checked action path, belongsTo and hasOne return an
object when found; hasMany and belongsToMany return arrays. orderBy
orders a has-many collection and where constrains it. ADL 26/27 own the
complete query syntax, missing-target behavior, and generated routes.
Signed R4 is explicit: ?include= never expands a remote reference in
0.5.1. The canonical reference string remains in the response. No bus fetch
is permitted by that include. The current loader iterates modeled
relationships, so include: person also leaves the example’s co-located
TEXT reference unchanged. This local non-expansion is an implementation limit;
it is not an extension of the remote-only ruling to every possible binding.
Included-row visibility (#1407). A row attached by ?include= is a row of
the target resource, and it is shown only as the target would show it on a
direct read by the same caller:
- The caller must pass the target’s
getpermission for that row, ownership included. A to-one relationship the caller may not read isnull; a row of a to-many relationship the caller may not read is left out. The parent response is otherwise unchanged. - A row that passes then goes through the target’s field security: write-only
fields are removed and field-level
read:restrictions apply. - This holds across domains. The platform
Useris guarded by the identity domain’s ownUserpermissions (list/get: [admin, system]), so an ordinary user’s?include=createdByisnull, and an administrator’s carries no password hash or token. - A target whose permissions the server does not know fails closed:
null, or an empty array. - Its values are typed as a direct read of the target types them (#1411):
an
integeris a JSON number, abooleana JSON boolean, ajsonfield an object, and the PostGIS sidecar columns are left out. Before #1411 every column but booleans arrived as a string ("1536","2.500000"), on PostgreSQL and SQLite alike. Repro 38 shows it.
An ownerField chain MUST NOT cross an unresolved reference. R4 requires
parse-time rejection with OWNER_CHAIN_CROSSES_REFERENCE, so permission
evaluation does not discover the unsupported traversal only after deployment.
The complete rejection fixture
uses ownerField: person.userId across a reference field. The checked strict
parser and domain submit both accept it; the required diagnostic is absent.
The inspected indirect-owner implementation follows local belongsTo data
and does not resolve reference-valued owner chains. The modeller rejects the
fixture for its older unsupported-reference and unknown-relationship rules,
which is not evidence of R4-specific conformance.
Observed include defects. Expanded related rows use string-valued raw
database cells even when the main row has typed integers and booleans. The
baseline’s where: { published: true } returns an empty array despite two
matching boolean rows; removing that filter returns titles A, then B, as
ordered. In a separate seeded case, direct Book get omits its password field,
but Author get with include: books exposes the field’s stored marker. The
marker is deliberately non-sensitive and inserted by SQL; this tests read
visibility, not password hashing. Before #1407, related output was filtered only
when the target was declared in the same domain, and then only by its field
rules; the target’s get permission was never checked. Both now apply, as the
visibility rules above state.
12.11 Complete examples and observable results
The complete local example uses only
the inherited grammar and therefore declares adl: "0.5.0" under R0-a:
# Complete baseline with all four relationship kinds.
adl: "0.5.0"
domain:
name: library
version: "1.0.0"
resources:
Author:
object:
id: { type: integer, primaryKey: true }
name: { type: string, required: true }
relationships:
books:
type: hasMany
target: Book
foreignKey: authorId
orderBy: { title: asc }
where: { published: true }
profile: { type: hasOne, target: Profile, foreignKey: authorId }
Book:
object:
id: { type: integer, primaryKey: true }
title: { type: string, required: true }
authorId: { type: integer, required: true }
published: { type: boolean, default: false }
relationships:
author: { type: belongsTo, target: Author, onDelete: restrict }
tags: { type: belongsToMany, target: Tag, timestamps: true }
Profile:
object:
id: { type: integer, primaryKey: true }
authorId: { type: integer, required: true, unique: true }
biography: { type: text }
relationships:
author: { type: belongsTo, target: Author, onDelete: cascade }
Tag:
object:
id: { type: integer, primaryKey: true }
label: { type: string }
The production parser and modeller accept this declaration. The generated
SQLite schema contains an integer authorId FK, a unique profile owner, and
a junction with composite (bookId, tagId) identity. Seeded SQL verifies
missing-parent and duplicate-profile rejection. Linking the same book and
tag twice succeeds twice but leaves one junction row. These checks do not
claim a successful end-to-end create path for every resource in this model.
| Additional complete input | Purpose and checked result |
|---|---|
composite.yaml | Ordered two-field identity; production and modeller acceptance |
party.yaml, clinical.yaml | Standalone 0.5.1 target/grant and reference declarations |
health.suite.yaml | Complete suite root; consumer listed first, provider activated first |
party.member.yaml, clinical.member.yaml | Complete member documents; inherit adl from the suite root |
reject-type.yaml | Deliberate unknown-type rejection; strict parser rejects, CLI only warns |
reject-owner-chain.yaml | R4 rejection expected; production acceptance is a recorded gap |
The suite members omit adl; the standalone domain files include it. Their
domain bodies are identical. The member files are not submitted as standalone
documents by this example. The reference suite returns canonical strings,
including after the deliberate out-of-band target deletion described above.
12.12 Evidence, applicability, and publication review
The verification record identifies source
revision 373c09d0, compatible adapter headers dcb5fa10, and the separate
hashes of clone-b’s existing Release artifacts. Only the chapter adapter was
compiled; no fresh production build of the inspected HEAD is asserted.
Draft 1 includes 70 production adapter cases, comprising 58 declaration cases and 12 disposable SQLite sequences, ten CLI/modeller commands, eleven independent modeller observations, and 36 passing focused existing tests. The assertions check successful setup and the reported behavior, including known defects. These are not 70 successful conformance vectors. PostgreSQL SQL is generated but not executed against a PostgreSQL server.
The verification record, including 28 reviewed sources, and reproduction instructions preserve the evidence. Publication review must reconcile static validation, target admission, cascade/write grants, physical names and binding metadata, owner-chain rejection, and include visibility/filter behavior. Binding migrations, privacy execution, remote access, all transports, and full delegated authorization remain outside the recorded execution coverage.