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

# References and links

## References

A field that names a fact of another table has the type `t.key(table)`.
Declare an `index` that starts with the field when you need the inverse read.
`t.key(() => table)` names a table declared later in the module, and
`t.key.self` names a fact of the same table.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { t, table } from "@bijectionhq/bijection";

export const customers = table({ name: t.string });
export const invoices = table(
  { customer: t.key(customers), placed: t.instant, total: t.decimal },
  { index: [["customer", "placed"]] },
);
export const categories = table({ name: t.string, parent: t.maybe(t.key.self) });
```

## Following references

Read the target with `ctx.get(customers(invoice.customer))`, which answers the
fact or `null`. Read the inverse as a bounded selection:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const recent = await ctx.list(
  invoices.where({ customer }).by("placed").descending().first(20),
);
```

Use `ctx.page(invoices.where({ customer }).by("placed"), { size, cursor })`
to hand the client one window and its `next` cursor. A selection no declared
index serves is refused with the index to add.

## Associations

Use a separate table when an association has its own fields or several facts
per endpoint. Key it by both endpoints so a pair is a point, and index the
other order for the reverse read:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
export const members = table(
  { team: t.key(teams), person: t.principal, since: t.instant },
  { key: ["team", "person"], index: [["person"]] },
);
// ctx.has(members({ team, person })), ctx.list(members.where({ person }).first(50))
```

Enforce participation rules in the mutation that writes the association.
`ctx.insert(members({ team, person }), fact)` refuses `Exists` for a pair
already present. A guard on `act.write(members, { transition: "create" })`
covers every creation of a membership. See [Reading](https://docs.bijection.com/database/reading.md) for paging the inverse.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.