|
| 1 | +--- |
| 2 | +title: "Stored relations" |
| 3 | +date: "2025-01-01" |
| 4 | +author: "" |
| 5 | +published: true |
| 6 | +--- |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +Stored relations change how relationships between discourse nodes are created and managed. |
| 11 | + |
| 12 | +Instead of being inferred from patterns in your Roam graph, **stored relations are created and deleted explicitly** and saved as data. This makes relations faster to query, more reliable, and easier to manage. |
| 13 | + |
| 14 | +Stored relations are the foundation for improved performance and a more usable Discourse context overlay. |
| 15 | + |
| 16 | +## What is a stored relation? |
| 17 | + |
| 18 | +A **stored relation** is an explicit relationship between two discourse nodes (for example, a claim supporting or opposing another claim). |
| 19 | + |
| 20 | +- Created directly in the [**Discourse context overlay**](./discourse-context-overlay) |
| 21 | +- Persisted as data in your graph |
| 22 | +- Independent of page structure or pattern matching |
| 23 | + |
| 24 | +Once created, stored relations behave consistently across queries, canvases, and overlays. |
| 25 | + |
| 26 | +## Why stored relations? |
| 27 | + |
| 28 | +Stored relations provide several benefits over pattern-based relations: |
| 29 | + |
| 30 | +- **Faster performance** |
| 31 | + - Relations are read directly from stored data |
| 32 | + - The global Discourse context overlay loads significantly faster |
| 33 | +- **More predictable behavior** |
| 34 | + - Relations do not disappear due to formatting or structural changes |
| 35 | + - Editing text or reorganizing blocks does not affect relations |
| 36 | +- **Clearer mental model** |
| 37 | + - Relations exist because you created them |
| 38 | + - Deleting a relation removes it explicitly |
| 39 | + |
| 40 | +## Creating stored relations |
| 41 | + |
| 42 | +Stored relations are created from the [**Discourse context overlay**](./discourse-context-overlay). |
| 43 | + |
| 44 | +Typical flow: |
| 45 | + |
| 46 | +1. Open the Discourse context overlay for a node |
| 47 | +2. Click **Add relation** |
| 48 | +3. Select the relation type |
| 49 | +4. Select the source and destination nodes |
| 50 | + |
| 51 | +The relation is immediately stored and available to all users who have enabled stored relations. |
| 52 | + |
| 53 | +## Viewing stored relations |
| 54 | + |
| 55 | +When stored relations are enabled: |
| 56 | + |
| 57 | +- The [Discourse Context Overlay](./discourse-context-overlay) shows **only stored relations** |
| 58 | +- Queries and canvases resolve relations from stored data |
| 59 | +- Pattern-based relations are ignored |
| 60 | + |
| 61 | +This ensures consistent and fast results. |
| 62 | + |
| 63 | +## Editing and deleting stored relations |
| 64 | + |
| 65 | +- Stored relations can be **deleted explicitly** from the Discourse context overlay |
| 66 | +- In most cases, editing a relation is equivalent to: |
| 67 | + - Deleting the old relation |
| 68 | + - Creating a new one |
| 69 | + |
| 70 | +Relation labels are referenced by node identity, so renaming a relation label updates all associated relations automatically. |
| 71 | + |
| 72 | +## Multi-user behavior |
| 73 | + |
| 74 | +Stored relations are shared across the graph: |
| 75 | + |
| 76 | +- All users with stored relations enabled see the same relations |
| 77 | +- Users without stored relations enabled will not see them |
| 78 | +- Mixed usage is supported temporarily during the transition period |
| 79 | + |
| 80 | +For details on migrating and mixed-mode behavior, see the [**stored relations migration**](./migration-to-stored-relations) documentation. |
| 81 | + |
| 82 | +## Current limitations and notes |
| 83 | + |
| 84 | +- Stored relations are **not inferred** from patterns |
| 85 | +- Creating or deleting patterns does not affect stored relations |
| 86 | +- Stored relations are currently opt-in during the transition period |
| 87 | + |
| 88 | +These limitations will be removed once stored relations become the default. |
| 89 | + |
| 90 | +## For the technically inclined |
| 91 | + |
| 92 | +Stored relations are implemented as: |
| 93 | + |
| 94 | +- One block per relation |
| 95 | +- Located at: `roam/js/discourse-graph/relations` |
| 96 | +- Relation data stored in the block’s hidden properties |
| 97 | +- Source and destination nodes referenced by UID |
| 98 | + |
| 99 | +This structure allows fast lookup, consistent rendering, and future extensions (metadata, provenance, annotations). |
| 100 | + |
| 101 | +## Future direction |
| 102 | + |
| 103 | +Stored relations will eventually replace pattern-based relations entirely. |
| 104 | + |
| 105 | +Once the transition period ends: |
| 106 | + |
| 107 | +- Stored relations will be the default |
| 108 | +- Pattern-based relations will be phased out |
| 109 | +- Migration will be handled automatically |
| 110 | + |
| 111 | +Until then, stored relations are available as an opt-in feature for users who want improved performance and reliability. |
0 commit comments