For example: a "way" class with a name[1:n] attribute. Mapping the UML class to SQL you can get something like:

create table way
   id serial not null primary key,
   geom geometry,
   other_attribute text

create table way_name
   way_id integer not null,
   name text not null,
   foreign key (way_id) references way (id) on update cascade on delete cascade,
   primary key way_name_pkey (way_id, name)

QGIS can automatic discovers the relationship between tables and you can set up a form for the "parent" entity (way) and include a subform-relation for the names. But it seems that creating a new way is a 2-step process in QGIS because when I edit a new way I can´t set its name. I have to close/accept the form, save layers changes, open the form again and (now that the way exists in the database) set the way name. Is there any solution for 1-step new features editing?

Obviously, I can do it if no foreign key exists but I can lost the relational integrity.

  • 2
    I'd always prefer to implement in-DB entry points for (multi)relational tables, i.e. Views, that centralize the rerouting of any data manipulation. makes the data model consistent and easy to maintain, and handles any client application. – ThingumaBob Jan 30 at 10:17

As you properly stated, the problem is, that there is no primary key created on the parent table (way), so no children (way_name) can be added.

To overcome this issue, QGIS offers a project wide setting Evaluate default values server side. This will pre-create properly defined default values in the form before it is saved.

See the data source section of the documentation.

Be aware, that you will need to save the parent (way) layer first (because the database will complain if you add children (way_names) referencing non existent objects).

There is a second option create transaction groups which will automatically make all layers from the same database editable at the same time and create a transaction. If the foreign keys are configured as deferred this will allow creating children before their parents and the referential integrity will only be checked at the end of the transaction (commit / save layer in QGIS).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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