QGIS Symbology – Setting Layer Symbology Based on Child Table Value

qgisrelatessymbology

I have a point layer (Dormouse) linked to a child geometry-less table (DormouseSurveyData) with a 1-n relationship. I am trying to set up the symbology of the point layer to change color dependent on if there is a value in the 'Presence' field of my child table.

I am aware that I could either join the tables or create a virtual layer to achieve this but I need the symbology to update as the records are updated so that when data is input in the field the symbology will dynamically update accordingly.

I have tried many different variations but the ones i thought most likely to work are below:

case
    when dbquery('DormouseSurveyData','Presence','Tube_ID = attribute($currentfeature,'id')')
        then color_rgb(0,200,0)
    
    when 'DormouseSurveyData_2acaff7f_d2b5_47a2_875c_0859987007d7.Tube_ID' =  'Dormouse.id' and 'DormouseSurveyData_2acaff7f_d2b5_47a2_875c_0859987007d7.Presence' = "False"
        then color_rgb(200,0,0)
    
    else color_rgb(0,0,200)
end

case
    when dbvalue('DormouseSurveyData','Presence','Tube_ID', 'ID')
        then color_rgb(0,200,0)
    when dbvalue('DormouseSurveyData','Presence','Tube_ID', 'ID')
        then color_rgb(200,0,0)
    else color_rgb(0,0,200)
end

The relationship links Dormouse.id to DormouseSurveyData.Tube_ID

Below are snippets of the two tables. Both with testing data.

When I run either expression in the data override for the fill color of my symbology i just get the 'else' result (ie blue).

Dormouse Table

DormouseSurveyData Table

Best Answer

Have you tried relation_aggregate function for classification of the layer?

E.g.

relation_aggregate(
relation:='relationdomousexblaablaablaa21321144124',aggregate:='max',expression:="precense") 

relation_aggregate function brings the id or what ever field you need "Up" to your visualization layer and then you can classify your data based on the other 1:N table values.

Related Question