I would like to create a cascading select in QGIS using the value relations widget. I'm using QGIS 3.14 (pi) and all layers are stored in a geopackage. The geopackage shown in this example can be downloaded here for testing (project file is in the gpkg).
I am able to do this in terms of limiting available values based on the value of a previously set attribute. However, the attribute table does not honour my choice.
I have a "parent" table with a 'key' and a 'type':
parent
key|type
1 |A
2 |B
3 |C
I have a "child" table as follows:
child
keyChild|typeChild|subType
1 |A |Yellow
1 |A |White
1 |A |Red
2 |B |Pink
2 |B |Orange
2 |B |Green
3 |C |Brown
3 |C |Blue
3 |C |Black
I create a point layer "test" with the attributes of 'testType' and 'testSubtype'.
In the properties > attribute form I set the widget for the 'type' attribute to "value relation" with the following settings:
I set the widget for the 'subtype' attribute to "value relation" with the following settings:
The filter expression is set to:
"typeChild" = current_value('testType')
This works to filter the options available when adding a new point feature:
However when I check the attribute table only the first option for that type shows:
I can alter the 'testSubtype' value in the attribute table by selecting 'order by value' in the Attributes Form setting:
The desired behaviour is for the attribute table to honour the user's selection and for that selection to persist. Other answers to similar questions on SE link to this post in the QGIS changelog. The workflow above mirrors the behaviour shown in the changelog but changes do not persist.
I'd like to know if this is reproducible behaviour. I've tested this on QGIS 3.2, 3.4 3.10 and 3.14. I get the same results in all versions.
The extra columns in the parent and child tables ('key' and 'keyChild') are for testing different options in the Attribute Form settings prompted by the answer to this issue on github.
Update
Gabriel's answer is accepted. I had failed to realise that the Filter Expression will still work regardless of what is set in the 'key' and 'value' settings of the widget. The key must be unique. Keeping everything the same as descirbed above just changing the key to 'subtype' worked as shown below: