mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-03 00:02:25 -05:00
This adds the possibility to manage data on a normalized relational database in N:M relations. On the relation editor in a form, the tools to add, delete, link and unlink work (also) on the linking table if a relation is visualized as N:M relation. Configuration is done through the fields tab where on the relation a second relation can be chosen (if there is a suitable relation in terms of a second relation on the linking table). Limitations =========== QGIS is not a database management system. It is based on assumptions about the underlying database system. In particular it expects * A `ON DELETE CASCADE` or similar measure on the second relation * Does not take care of setting the primary key when adding features. Either users need to be instructed to set them manually or - if it's a database derived value - the layers need to be in transaction mode (currently only activatable through the API)
62 lines
1.6 KiB
SQL
62 lines
1.6 KiB
SQL
-- Table: qgis_test.authors
|
|
|
|
-- DROP TABLE qgis_test.authors;
|
|
|
|
CREATE TABLE qgis_test.authors
|
|
(
|
|
pk serial NOT NULL,
|
|
name character varying(255),
|
|
CONSTRAINT authors_pkey PRIMARY KEY (pk),
|
|
CONSTRAINT authors_name_key UNIQUE (name)
|
|
);
|
|
|
|
-- Table: qgis_test.books
|
|
|
|
-- DROP TABLE qgis_test.books;
|
|
|
|
CREATE TABLE qgis_test.books
|
|
(
|
|
pk serial NOT NULL,
|
|
name character varying(255),
|
|
CONSTRAINT books_pkey PRIMARY KEY (pk),
|
|
CONSTRAINT books_name_key UNIQUE (name)
|
|
);
|
|
|
|
-- Table: qgis_test.books_authors
|
|
|
|
-- DROP TABLE qgis_test.books_authors;
|
|
|
|
CREATE TABLE qgis_test.books_authors
|
|
(
|
|
fk_book integer NOT NULL,
|
|
fk_author integer NOT NULL,
|
|
CONSTRAINT books_authors_pkey PRIMARY KEY (fk_book, fk_author),
|
|
CONSTRAINT books_authors_fk_author_fkey FOREIGN KEY (fk_author)
|
|
REFERENCES qgis_test.authors (pk) MATCH SIMPLE
|
|
ON UPDATE NO ACTION ON DELETE CASCADE,
|
|
CONSTRAINT books_authors_fk_book_fkey FOREIGN KEY (fk_book)
|
|
REFERENCES qgis_test.books (pk) MATCH SIMPLE
|
|
ON UPDATE NO ACTION ON DELETE CASCADE
|
|
);
|
|
|
|
INSERT INTO qgis_test.authors(name)
|
|
VALUES
|
|
('Erich Gamma'),
|
|
('Richard Helm'),
|
|
('Ralph Johnson'),
|
|
('John Vlissides'),
|
|
('Douglas Adams'),
|
|
('Ken Follett'),
|
|
('Gabriel García Márquez');
|
|
|
|
INSERT INTO qgis_test.books(name)
|
|
VALUES
|
|
('Design Patterns. Elements of Reusable Object-Oriented Software');
|
|
|
|
INSERT INTO qgis_test.books_authors(fk_book, fk_author)
|
|
VALUES
|
|
(1, 1),
|
|
(1, 2),
|
|
(1, 3),
|
|
(1, 4);
|