summaryrefslogtreecommitdiff
path: root/archaeological_finds/models_treatments.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-20 18:22:17 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-20 18:22:17 +0100
commit650737195d8edfcaca50a1e6d41a8e8b605f3f55 (patch)
tree71a409727bb569887f9a055dcef5cfd6de1c6f8a /archaeological_finds/models_treatments.py
parent994091c2226229fa7fdc1ea9e6cc1bc4e6a27b71 (diff)
downloadIshtar-650737195d8edfcaca50a1e6d41a8e8b605f3f55.tar.bz2
Ishtar-650737195d8edfcaca50a1e6d41a8e8b605f3f55.zip
Fix treatment view (refs #3426)
Diffstat (limited to 'archaeological_finds/models_treatments.py')
-rw-r--r--archaeological_finds/models_treatments.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index dacfbfdfc..d8d51e28c 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -310,9 +310,10 @@ class FindUpstreamTreatments(AbsFindTreatments):
WITH RECURSIVE rel_tree AS (
SELECT id AS find_id, upstream_treatment_id, downstream_treatment_id,
1 AS level,
- array[upstream_treatment_id] AS path_info
+ ARRAY[]::integer[] AS path_info
FROM archaeological_finds_find
- WHERE upstream_treatment_id is null
+ WHERE upstream_treatment_id is NULL AND
+ downstream_treatment_id is NOT NULL
UNION ALL
SELECT c.id AS find_id, c.upstream_treatment_id,
c.downstream_treatment_id,
@@ -320,8 +321,10 @@ class FindUpstreamTreatments(AbsFindTreatments):
FROM archaeological_finds_find c
JOIN rel_tree p
ON c.upstream_treatment_id = p.downstream_treatment_id
- AND c.upstream_treatment_id !=
- ALL(p.path_info[0:array_upper(p.path_info, 1)-1])
+ AND (p.path_info = ARRAY[]::integer[] OR
+ NOT (c.upstream_treatment_id =
+ ANY(p.path_info[0:array_upper(p.path_info, 1)-1]))
+ )
)
SELECT DISTINCT find_id, path_info, level
FROM rel_tree ORDER BY find_id;
@@ -364,9 +367,10 @@ class FindDownstreamTreatments(AbsFindTreatments):
WITH RECURSIVE rel_tree AS (
SELECT id AS find_id, downstream_treatment_id, upstream_treatment_id,
1 AS level,
- array[downstream_treatment_id] AS path_info
+ ARRAY[]::integer[] AS path_info
FROM archaeological_finds_find
- WHERE downstream_treatment_id is null
+ WHERE downstream_treatment_id is NULL AND
+ upstream_treatment_id is NOT NULL
UNION ALL
SELECT c.id AS find_id, c.downstream_treatment_id,
c.upstream_treatment_id,
@@ -374,8 +378,10 @@ class FindDownstreamTreatments(AbsFindTreatments):
FROM archaeological_finds_find c
JOIN rel_tree p
ON c.downstream_treatment_id = p.upstream_treatment_id
- AND c.downstream_treatment_id !=
- ALL(p.path_info[0:array_upper(p.path_info, 1)-1])
+ AND (p.path_info = ARRAY[]::integer[] OR
+ NOT (c.downstream_treatment_id =
+ ANY(p.path_info[0:array_upper(p.path_info, 1)-1]))
+ )
)
SELECT DISTINCT find_id, path_info, level
FROM rel_tree ORDER BY find_id;