MerginMaps / mobile

Mobile app for Mergin Maps 📲. Open QGIS projects and manage vector data on your phone, even offline 📶 (Android/iOS/Windows app)
https://merginmaps.com
GNU General Public License v2.0
293 stars 64 forks source link

Warn if user has 1-N relation and FID #1636

Open saberraz opened 2 years ago

saberraz commented 2 years ago

In most cases, users will use the FID of a GeoPackage as the field for their Parent layer in the 1-N relation. The problem comes when you sync the project: the FID gets overwritten by Geodiff which subsequently breaks the relation between the correct FID and the Child layer.

We need to detect if FID is used for a relation, and if so, update the relation to use the new FID assigned to the layer.

wonder-sk commented 2 years ago

This is something that should be handled in the Mergin QGIS plugin. Geodiff has no way of knowing about relations, and even if it knew because of foreign keys, these are not supported yet https://github.com/lutraconsulting/geodiff/issues/39

If we want to have Input to correctly handle this situation, we should:

PeterPetrik commented 2 years ago

They can use relations if they do NOT use the feature FID as reference key. Best it to have extra UUID auto-generated column in the parent table, so the geodiff rebasing does not mess up with those...

rmarzocchi84 commented 2 years ago

In my case the Parent reference defined in QGIS is lost on the Input app and I cannot add record whih are referenced to parent layer.

Here my definition on QGIS: image

QGIS works correctly:

image

Input doesn't work: InkedScreenshot_20210929-152913_LI

I do not understand if it is related to this bug.

mdouchin commented 2 years ago

I would also encourage a lot to use UUIDS columns as references, and never user FID (ou PostgreSQL id serials). In most cases, the performance impact will be negligeable, and this will ease a lot the workflow. I always use UID columns in the relations definition.

FIDs and PostgreSQL serials will still be used to have integer features ids (better for performances).

By the way, thanks a lot for releasing and maintaining geodiff.

PeterPetrik commented 10 months ago

QGIS mergin plugin has already validator for this case (https://github.com/MerginMaps/qgis-mergin-plugin/pull/380) and in the mobile app we can possibly add a warning to the project warning dialog (similarly to invalid CRS or missing layers), but nothing more. Do we want to do it or shall we just close this issue?