6

I have a PostgreSQL/PostGIS database with a base table (Pois_points) and two subtables which constitute a many-to-many relationship with the base table, as you can see on the picture below (click on Many to many relationships).

I want to build a QGIS form that depicts this relationship between the tables when adding and editing items. I have seen examples of a one-to-many relationship in QGIS, which is relatively easy. But many-to-many is not documented or maybe not possible at all?

Many to many relationships

2
  • 1
    Could you please add QGIS version & OS? Aug 12, 2016 at 8:22
  • I'm sorry: QGis version 2.16.1, installed on Windows 10, 64bits
    – Pim Verver
    Aug 13, 2016 at 11:25

2 Answers 2

2

If you don't mind having a bit of bad design in your database, you can create the relation between your Pois_points and History tables using the relational value widget and check "allow multiple selections". You'll have to create a new column in your Pois_points table in which foreign keys will be stored as varchar arrays.

If you want a clean N:M relationship you can try this solution but you'll have to write some Python.

Since this pull request it should now be possible to create N:M relationship in QGIS easily. Documentation can be found here.

Unfortunately I can't make it working so I opened a ticket.

N:M relationship configuration

0

Try creating a relationship for poi-pos and the ps-points-history table, then a relationship for the history table and pos-points-history table.

2
  • The relationships themselves are allready defined on the database level. What I am looking for is how to make a QGIS form of the attributes of each feature displayed in QGIS, where for instance the selected history names are viewable and where you can change the selection based of a dropdown list of available history names. If its a one-to-many relationship, that's not so difficult, if it's a many-to-many then I haven't seen any documented working example. I have tried on my own, but without any satisfying result.
    – Pim Verver
    Aug 13, 2016 at 11:30
  • Yeh what I'm saying is in QGIS you define both relationships separately, then set up the one form and you should be right. From your question I assume you can already setup a relationship in QGIS and set up the forms, if not I can give you help on tha
    – Liam G
    Aug 13, 2016 at 11:40

Your Answer

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

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