In Spatialite (3.0.1), having a normal (non-spatial) table, I would like to relate it to two different spatial tables, with different geometries types (multipolygons and polylines), using the same column as a foreign key, and constraint it to their primary keys.
The general idea would be to, while inserting a new record in the non-spatial table, one can choose to relate it to a line or a polygon from two distinct spatial tables.
Example:
CREATE TABLE sp1_polygons
poly_id TEXT NOT NULL PRIMARY KEY;
SELECT AddGeometryColumn(
'sp1_polygons', 'geometry',
27493, 'MULTIPOLYGON', 'XY');
CREATE TABLE sp2_lines
poly_id TEXT NOT NULL PRIMARY KEY;
SELECT AddGeometryColumn(
'sp2_lines', 'geometry',
27493, 'MULTILINESTRING', 'XY');
CREATE TABLE t1 (
t1_id INTEGER NOT NULL PRIMARY KEY,
geo_id TEXT NOT NULL,
CONSTRAINT fk_sp1
FOREIGN KEY (geo_id)
REFERENCES sp1 (sp1_id)),
CONSTRAINT fk_sp2
FOREIGN KEY (geo_id) -- Equal to before
REFERENCES sp2 (sp2_id));
In my particular case, the non-spatial table represent management actions (harvesting, planting, cutting, fixing, etc...) in a farm, while the spatial tables represent homogeneus plots (polygons) to be managed (farmland, forest, natural vegetation), or homogeneus lines (water streams, natural fences, etc...).