OR position(bnd_name in lower(name->'name')) > 0)
AND placex.class = 'place' AND placex.type = bnd.extratags->'place'
AND placex.osm_type = 'N'
- AND placex.linked_place_id is null
+ AND (placex.linked_place_id is null or placex.linked_place_id = bnd.place_id)
AND placex.rank_search < 26 -- needed to select the right index
AND placex.type != 'postcode'
AND ST_Covers(bnd.geometry, placex.geometry)
WHERE placex.class = 'place' AND placex.osm_type = 'N'
AND placex.extratags ? 'wikidata' -- needed to select right index
AND placex.extratags->'wikidata' = bnd.extratags->'wikidata'
- AND placex.linked_place_id is null
+ AND (placex.linked_place_id is null or placex.linked_place_id = bnd.place_id)
AND placex.rank_search < 26
AND _st_covers(bnd.geometry, placex.geometry)
ORDER BY lower(name->'name') = bnd_name desc
OR (bnd.rank_address = 0 and placex.rank_search = bnd.rank_search))
AND placex.osm_type = 'N'
AND placex.class = 'place'
- AND placex.linked_place_id is null
+ AND (placex.linked_place_id is null or placex.linked_place_id = bnd.place_id)
AND placex.rank_search < 26 -- needed to select the right index
AND placex.type != 'postcode'
AND ST_Covers(bnd.geometry, placex.geometry)
DELETE FROM place_addressline WHERE place_id = NEW.place_id;
result := deleteRoad(NEW.partition, NEW.place_id);
result := deleteLocationArea(NEW.partition, NEW.place_id, NEW.rank_search);
- UPDATE placex set linked_place_id = null, indexed_status = 2
- where linked_place_id = NEW.place_id;
- -- update not necessary for osmline, cause linked_place_id does not exist
NEW.extratags := NEW.extratags - 'linked_place'::TEXT;
linked_place := NEW.linked_place_id;
NEW.linked_place_id := OLD.linked_place_id;
+ -- Remove linkage, if we have computed a different new linkee.
+ UPDATE placex SET linked_place_id = null, indexed_status = 2
+ WHERE linked_place_id = NEW.place_id
+ and (linked_place is null or linked_place_id != linked_place);
+ -- update not necessary for osmline, cause linked_place_id does not exist
+
IF NEW.linked_place_id is not null THEN
NEW.token_info := null;
{% if debug %}RAISE WARNING 'place already linked to %', OLD.linked_place_id;{% endif %}
Feature: Updates of linked places
Tests that linked places are correctly added and deleted.
+ Scenario: Linking is kept when boundary is updated
+ Given the places
+ | osm | class | type | name | geometry |
+ | N1 | place | city | foo | 0 0 |
+ And the places
+ | osm | class | type | name | admin | geometry |
+ | R1 | boundary | administrative | foo | 8 | poly-area:0.1 |
+ When importing
+ Then placex contains
+ | object | linked_place_id |
+ | N1 | R1 |
+ When updating places
+ | osm | class | type | name | name+name:de | admin | geometry |
+ | R1 | boundary | administrative | foo | Dingens | 8 | poly-area:0.1 |
+ Then placex contains
+ | object | linked_place_id |
+ | N1 | R1 |
+
+
Scenario: Add linked place when linking relation is renamed
Given the places
| osm | class | type | name | geometry |