2

As far as I know, the "Value Relation Widget" is supposed to store the records from the field designated as KEY COLUMN in the attribute table, while the records from the field designated as VALUE COLUMN are the ones that should only be displayed in the attribute form instead of the records from the field designated as KEY COLUMN, i.e. as a sort of a "hint" to the user. In my experience, the widget does not behave as expected, and I don't know if I'm doing something wrong or just misunderstanding how it works.

Here's an example (QGIS version 3.22.5 "Białowieża"):

I created a Geopackage named "test_value_relation_widget.gpkg".

Then I created a table named "places_types" with no geometry and two fields: "type_id" and "type_name":

creating table "places_types"

Then I put some records into both fields:

putting records in the table "places_types"

Then I created another table named "places" with three fields: "place_name", "place_type_VR_key_fid" and "place_type_VR_key_type_id". The second and the third fields should be used to test two different scenarios:

creating table "places"

In the first case, in the Value Relation widget, the Key column points to the "fid" of the "places_types" table, and the Value column points to the "type_name" field:

adjusting the Value Relation widged scenario 1

In the second case, in the Value Relation widget, the Key column points to the "type_id" field of the "places_types" table, and the Value column again points to the "type_name" field:

adjusting the Value Relation widged scenario 2

Then I created some points and selected the values. As expected, I saw the records from the Value column displayed in the attribute form:

attribute form

As a result, in both cases, the attribute table does not contain the records from the fields, designated as Key column(s) but those from the Value column:

attribute table

Even after saving the project to the Geopackage, restarting QGIS, and reopening the project, nothing changes.

Please advise.

PS I'm somewhat surprised that even if the data type of a field is defined as an integer, the Value Relation widget can store a text string in it, for example, "village" instead of "1", "town" instead of "2" etc.

2 Answers 2

2

this is the normal behavior of QGIS, since in the table you can edit the values also and it will be still offering a drop down list to choose a value from the relation widget. if you open the table in the databasemanger, you will see, that only the keys are stored in the table...

enter image description here

enter image description here

0

"Besten Dank!" for your reply, you solved my problem quickly and competently.

I would just like to provide some additional information that might be helpful to other unsuspecting people like me.

When someone exports the layer to another format via the layer panel ...

exporting via the layers panel

... he/she still gets an attribute table with the records from the Value column:

result when exporting via the layers panel

But if the export is done through the DB Manager ...

exporting via the DB manager

... the attribute table will contain the records from the Key column:

result of export via the DB manager

2
  • 2
    the export dialog (not the one from DB Manager) has a checkbox to choose to "Replace all selected raw field values by displayed values", if exporting to excel this is selected be default (explaining the behavior you notice) but you could uncheck it to export the key value. (the state of this option differ depending on the export format, it's better to always check it to get the result youi want)
    – J.R
    Commented Jan 25 at 10:07
  • 2
    Also I'm not sure if this "answer" should be edited to be more compliant with site guideline or put as an edit to the original question….
    – J.R
    Commented Jan 25 at 10:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.