Skip to content

Commit 0e174a4

Browse files
committed
Add diagram describing the mapping between Form and FormDocument objects
This was pretty confusing and creating this doc helped made it clearer to understand.
1 parent b1c20a3 commit 0e174a4

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Form and FormDocument object mappings
2+
3+
## What gets turned into what?
4+
5+
```mermaid
6+
graph LR
7+
Form -- transformed into --> FormDocument
8+
Page -- transformed into --> Step
9+
Condition -- transformed into --> RoutingCondition
10+
```
11+
12+
Forms are transformed into Pages, and Pages are transformed into Steps.
13+
14+
Form has a method to transform into a FormDocument called [as_form_document](https://github.com/alphagov/forms-admin/blob/main/app/models/form.rb#L147-L155).
15+
16+
The Page to Step transformation by [this method in the Page](https://github.com/alphagov/forms-admin/blob/main/app/models/page.rb#L94) class.
17+
18+
It basically puts the positional attributes such at the position and ID at the top-level of the step and the other attributes within the "data" field. We add a "type" which for now is always "question_page", but could be "question_set" in the future. This maps mainly onto Option 1 in [this RFC](https://github.com/alphagov/forms/discussions/174) from a while ago.
19+
20+
## How they relate
21+
22+
### Forms
23+
```mermaid
24+
graph TD
25+
A[Form] -- has many --> B[Page]
26+
B <-- has many and belongs to --> C[Condition]
27+
D[Routing Condition] -- is a --> C
28+
E[Check Condition] -- is a --> C
29+
F[Goto Condition] -- is a --> C
30+
G[Routing Page] -- is a --> B
31+
H[Check Page] -- is a --> B
32+
I[Goto Page] -- is a --> B
33+
D -- points to --> G
34+
E -- points to --> H
35+
G -- points to --> I
36+
```
37+
38+
### FormDocuments
39+
```mermaid
40+
graph TD
41+
A[FormDocument] -- has many --> B[Steps]
42+
B <-- has many and belongs to --> C[Routing Conditions]
43+
C -- check_step_id --> B
44+
C -- routing_step_id --> B
45+
C -- goto_step_id --> B
46+
```
47+
48+
A FormDocument would include the following:
49+
50+
```json
51+
{
52+
"step": {
53+
id: 18
54+
/* ..other steps attributes... */
55+
"routing_conditions": [
56+
{
57+
"id": 3,
58+
"check_step_id": 18,
59+
"routing_step_id": 18,
60+
"goto_step_id": null,
61+
"answer_value": "Yes",
62+
"created_at": "2024-08-02T08:54:07.479Z",
63+
"updated_at": "2024-08-02T08:54:07.479Z",
64+
"skip_to_end": true,
65+
"validation_errors": []
66+
}
67+
]
68+
}
69+
}
70+
```
71+
72+
The `step.id`, is the id of the step (which is a `Page` in active record but stored as `step` in the `FormDocument`).
73+
74+
`step.routing_conditions` contains an array of `Conditions` linked to the `step` through `routing_step_id`. `check_step_id` and `goto_step_id` are references to other `steps` in the form. These are just references, not extra conditions. All Conditions have a `routing_step_id` which links them to a `Step`.

0 commit comments

Comments
 (0)