How to implement feature update in real time with a relation

I am looking for functionality in Qfield like the one described at
feature-live-update
I have defined some relations in my Qgis project and they are working well.
I need to sum all the “children” and validate that a certain attribute sum up to 100.
I created a virtual field, added it to the form, and used the expression below:

relation_aggregate(
  'obs_child_6_obs_point_id_obs_point__point_id', 
  'sum',
  "perc"
)

“perc” is an attribute of the “children”.
This works well in QGIS but not in Qfield.
Any workaround? suggestions>?


Imported from GitHub discussion by @rosaguilar on 2024-05-27T15:31:52Z

Hello rosaguilar,

It’s best to avoid a virtual field and use an actual field instead. Could you try the expression below for real-time calculations? Also, ensure that you have the “Apply default value on update” activated:

aggregate( layer:='child layer', aggregate:='sum', expression:="perc", filter:="uuid_parent" = attribute(parent,'uuid') )

If you could provide a sample of the project, it would help better.


Imported from GitHub comment by @SeqLaz on 2024-05-28T07:06:28Z

Hi, SeqLaz
Thanks a lot. It works with an actual field. The key is that the value does not get automatically updated after each child insertion. When another field in the parent form is edited, then the value is computed. Foe now, that is good for me. Thanks.


Imported from GitHub comment by @rosaguilar on 2024-05-28T09:01:23Z

Hi rosaguilar and SeqLaz ,
I have the same question, but I’m looking for the missing piece you’re asking in the end: how to make the value actually update after each child insertion? This is necessary to validate live in the field if my numbers add up.
I’ve tried many workaround, but so far, the best I came up with is to force a field update by adding a dummy radio button… an extra step in the field, and not particularly pretty.

Any tips would be welcomed.
Thanks!


Imported from GitHub comment by @Horizen89 on 2025-04-17T00:03:15Z

Hi Horizen89 , actually the best practice is that, add a field with a checkbox to compute the update at the end of adding children’s features and have activated Apply default values on Update on the fields where you want to perform these calculations.


Imported from GitHub comment by @SeqLaz on 2025-04-17T17:48:36Z

Hi SeqLaz ,
This is what I meant with the radio button. It works, but it’s an extra step.
Thanks for your input, I’ll keep this solution at this point!


Imported from GitHub comment by @Horizen89 on 2025-04-17T18:45:47Z