5

I have read the QField support on how to add a series of pictures to a feature. I've also read other threads and GIS Stack Exchange questions and answers on this: e.g., Setting QField for 1:n photos. However, I am still confused and unable to get this working properly and was hoping that someone could provide a detailed explanation that may help others in this process.

Step 1: I create the relation between the Referenced 'parent layer' (= Wetland Survey) and the referencing 'child layer' (= Wetland_pics):

Properties, Add Relation - screen shot

I am not entirely clear on what 'uuid' actually is here. I know that it is a Universal Unique Identifier, but is this necessary? Why couldn't I use my site.code? I notice that using site.code()as a default value gives an error, where uuid() gives an identifier - so the system must recognize uuid for this function. This is not my primary question, but understanding this seems important in relation to the primary keys (not entirely sure of what they are).

Step 2. Building the form layout

a. Drag and Drop, set the uuid (parent relation):

uuid form layout

b. Drag and Drop, set the Wetland Pictures (child relation):

Child relation form layout

Step 3. Setting drag and drop form in the child table ('Wetland_pics') - set path to attachment widget type:

Child table form layout - Wetland_pics

Step 4. Testing the form:

Screen capture of the resulting form in QGIS

Screen capture of the resulting form in QField beta Windows version

The form looks fine, but I am unable to select or type anything in the "Wetland Pictures" fields in QGIS. I'm trialing the form in QField beta windows version (second image) and you can see that I get the message "Cannot add child feature: parent primary keys are not available". This is what leads me to suspect that this has something to do with uuid.

1
  • Try to use your "fid" field of Wetland Survey layer as foreign key for relation instead of "uuid" and change "side.code.pic" type to integer. I may be wrong but using dots in fields names is not a realy good way
    – BlackTesta
    Commented Apr 27, 2021 at 13:43

1 Answer 1

3

In your example, 'uuid' is a, attribute name. uuid() is a recognised function. You appear to have taken your attribute name 'site.code' and added parentheses at the end in the hope it will return something. It will not, because unless you have defined the funciton site.code(), it does not exist.

As to the 1:n setup….

Step 2, parent ‘uuid’ attribute settings look correct. But I don’t understand what you are doing with the field ‘Wetland Pictures’ - this does not need to exist. Your pictures are displayed using the ‘path’ attribute of your child table – this appears as a subform in your main form. Perhaps I’m confused, but this looks wrong to me.

Step 3, your settings for ‘path’ look correct. But you don’t show your settings for ‘site.code.pic’. This should be a ‘Relation reference’ widget, with the relation set to the name of the relation you created in Step 1 (I note you have this set to be generated automatically. That’s fine, so as long as there are not numerous other relations the autogenerated name should easy enough to recognise and select from a drop down list immediately below the widget type box (set to ‘Relation reference’).

Step 4. Site.code is Null because you have not set a valid default value.(but that does not affect 1:n photos). Also note in your subform ‘Wetland Pictures’ site.code.pic is not popoulated. It should be automatically filled in with the same uuid as the Wetland Survey (see my comments regarding step 3 above).

If this doesn't help, I can probably fix it pretty quickly if you want to share the project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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