You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/layer/one-to-n-relations/index.md
+39-20Lines changed: 39 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -7,53 +7,72 @@ You can clone these projects to take a closer look on 1-N relations:
7
7
- Adding multiple photos to a single feature: <MerginMapsProjectid="documentation/forms_multiple_photos" />
8
8
:::
9
9
10
-
It is often the case that you have a set of spatial features and you want to record some parameters every now and then. For example, there is a GIS layer representing the manholes and the surveyors carry out regular inspections of the manholes. Instead of duplicating the manhole layer and recording each inspection, you can create a non-spatial table and store each inspection as a new row.
10
+
It is often the case that you have a set of spatial features and you want to record their status every now and then. For example, there is a GIS layer representing the manholes and the surveyors carry out regular inspections of the manholes using <MainPlatformNameLink />. Instead of duplicating the manhole layer and recording each inspection as a new feature, inspections can be recorded in a non-spatial table that is linked to the spatial layer. This way, multiple records can be linked to one feature.
11
11
12
-
The image below shows the manholes locations:
12
+
The image below shows the manhole locations and a form with listed inspections in <MobileAppName />.
In a separate [non-spatial table](../working_with_nonspatial_data/), we can record the inspections:
24
+
This layer contains only information about the manholes. `Manhole UUID` values are generated using [`uuid()` function as a default value](../attach-multiple-photos-to-features/) when a feature is created. This ensures that these values are **unique** even when multiple surveyors capture new features at the same time. This field will be used to link inspections and manholes.
**Why UUID?** FID can be changed during [synchronisation](../../manage/synchronisation/#synchronisation). As a result, records can end up being linked to wrong features.
23
28
24
-
In QGIS, we are using the **Manhole ID** from the point layer and the inspection table to create a 1-N relation between the two tables.
29
+
On the other hand, <QGISHelpver="latest"link="user_manual/expressions/functions_list.html#uuid"text="UUID" /> (Universally Unique Identifier) is generated to be unique and will not be changed when synced. Therefore, we recommend always using UUID to link layers.
30
+
:::
31
+
32
+
Inspections are recorded in a separate [non-spatial table](../working_with_nonspatial_data/) with attribute table such as:
In this table, all information about the inspections are recorded. `Manhole UUID` is filled in automatically based on a 1-N relation that we will set up in QGIS.
25
42
26
43
The same principle can be used when you want to capture [multiple photos for a single feature](../attach-multiple-photos-to-features/).
27
44
28
45
29
-
## Project setup in QGIS
46
+
## How to set up 1-N relations in QGIS project
30
47
You can follow this example by cloning <MerginMapsProjectid="documentation/forms_one-to-many-relations" />.
31
48
49
+
:::tip
50
+
Make sure that your survey layer has a **unique UUID** field to create the link correctly. You will find detailed steps how to set it up in [How to Attach Multiple Photos to Features](../attach-multiple-photos-to-features/)
51
+
:::
52
+
32
53
To configure 1-N relations in QGIS:
33
54
1. From the main menu, select **Projects** > **Properties ...**
34
55
2. In the **Relations** tab, select **Add Relation**

36
57
3. A new window will appear, where we can define the parent and child layers and the fields to link the two layers:
37
58
-**Name** is the name of the relation, e.g. `Inspection`
38
59
-**Referenced (parent)** is the spatial layer `manhole_locations`
39
-
-**Field 1** of the **Referenced (parent)** is the field `Manhole` that contains the ID
60
+
-**Field 1** of the **Referenced (parent)** is the field `Manhole UUID` that contains the **unique** UUID
40
61
-**Referencing (child)** is the non-spatial layer `inspections`
41
-
-**Field 1** of the **Referencing (child)** layer is the `Manhole ID`, which acts as a foreign key to link inspections to spatial features.
62
+
-**Field 1** of the **Referencing (child)** layer is the `Manhole UUID`, which acts as a foreign key to link inspections to spatial features
42
63
43
-

64
+

44
65
45
66
4. Right-click on the survey layer, select **Properties** and go to the **Attributes** form tab.
46
67
5. Drag and drop the **Inspections** relation to the **Form Layout**.
68
+

47
69
48
-

49
-
50
-
This now allows you to add multiple inspections for each manhole location (**manhole_locations** point layer). The inspections records will be stored in the **inspections** table.
51
-
52
-
When you open the form for an existing record in the **manhole_locations** point layer, you will be able to see the existing inspection records and optionally add, delete or edit the records:
70
+
Now you can add multiple inspections for each manhole location. The inspections records will be stored in the `inspections` table.
53
71
54
-

72
+
When you open the form for an existing record in the `manhole_locations` point layer, it will display existing inspection records and you can also add, delete or edit the records:
73
+

55
74
56
75
In <MobileAppName />, the form will look like this:
57
76
58
-

77
+

0 commit comments