Skip to content

Commit ae4a553

Browse files
Corrected issue where I tried to be too fancy with approach to pkid's
1 parent 20eeb69 commit ae4a553

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

django_postgresql_dag/models.py

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
from .transformations import _filter_order
2222

2323
LIMITING_FK_EDGES_CLAUSE_1 = (
24-
"""AND second.{fk_field_name}_{pk_name} = %(limiting_fk_edges_instance_pk)s"""
24+
"""AND second.{fk_field_name}_id = %(limiting_fk_edges_instance_pk)s"""
2525
)
26-
LIMITING_FK_EDGES_CLAUSE_2 = """AND {relationship_table}.{fk_field_name}_{pk_name} = %(limiting_fk_edges_instance_pk)s"""
26+
LIMITING_FK_EDGES_CLAUSE_2 = """AND {relationship_table}.{fk_field_name}_id = %(limiting_fk_edges_instance_pk)s"""
2727

2828
LIMITING_FK_NODES_CLAUSE_1 = """"""
2929
LIMITING_FK_NODES_CLAUSE_2 = """"""
@@ -34,35 +34,35 @@
3434
# DISALLOWED_DESCENDANTS_NODES_CLAUSE_1 = """AND second.parent_pk <> ALL(%(disallowed_descendants_node_pks)s)""" # Used for descendants and downward path
3535
# DISALLOWED_DESCENDANTS_NODES_CLAUSE_2 = """AND {relationship_table}.parent_pk <> ALL(%(disallowed_descendants_node_pks)s)"""
3636

37-
DISALLOWED_ANCESTORS_NODES_CLAUSE_1 = """AND first.parent_{pk_name} <> ALL(%(disallowed_ancestors_node_pks)s)""" # Used for ancestors and upward path
38-
DISALLOWED_ANCESTORS_NODES_CLAUSE_2 = """AND {relationship_table}.parent_{pk_name} <> ALL(%(disallowed_ancestors_node_pks)s)"""
37+
DISALLOWED_ANCESTORS_NODES_CLAUSE_1 = """AND first.parent_id <> ALL(%(disallowed_ancestors_node_pks)s)""" # Used for ancestors and upward path
38+
DISALLOWED_ANCESTORS_NODES_CLAUSE_2 = """AND {relationship_table}.parent_id <> ALL(%(disallowed_ancestors_node_pks)s)"""
3939

40-
DISALLOWED_DESCENDANTS_NODES_CLAUSE_1 = """AND first.child_{pk_name} <> ALL(%(disallowed_descendants_node_pks)s)""" # Used for descendants and downward path
41-
DISALLOWED_DESCENDANTS_NODES_CLAUSE_2 = """AND {relationship_table}.child_{pk_name} <> ALL(%(disallowed_descendants_node_pks)s)"""
40+
DISALLOWED_DESCENDANTS_NODES_CLAUSE_1 = """AND first.child_id <> ALL(%(disallowed_descendants_node_pks)s)""" # Used for descendants and downward path
41+
DISALLOWED_DESCENDANTS_NODES_CLAUSE_2 = """AND {relationship_table}.child_id <> ALL(%(disallowed_descendants_node_pks)s)"""
4242

4343

4444
ALLOWED_ANCESTORS_NODES_CLAUSE_1 = """AND first.parent_pk = ANY(%(allowed_ancestors_node_pks)s)""" # Used for ancestors and upward path
45-
ALLOWED_ANCESTORS_NODES_CLAUSE_2 = """AND {relationship_table}.parent_{pk_name} = ANY(%(allowed_ancestors_node_pks)s)"""
45+
ALLOWED_ANCESTORS_NODES_CLAUSE_2 = """AND {relationship_table}.parent_id = ANY(%(allowed_ancestors_node_pks)s)"""
4646

47-
ALLOWED_DESCENDANTS_NODES_CLAUSE_1 = """AND first.child_{pk_name} = ANY(%(allowed_descendants_node_pks)s)""" # Used for descendants and downward path
48-
ALLOWED_DESCENDANTS_NODES_CLAUSE_2 = """AND {relationship_table}.child_{pk_name} = ANY(%(allowed_descendants_node_pks)s)"""
47+
ALLOWED_DESCENDANTS_NODES_CLAUSE_1 = """AND first.child_id = ANY(%(allowed_descendants_node_pks)s)""" # Used for descendants and downward path
48+
ALLOWED_DESCENDANTS_NODES_CLAUSE_2 = """AND {relationship_table}.child_id = ANY(%(allowed_descendants_node_pks)s)"""
4949

5050
ANCESTORS_QUERY = """
5151
WITH RECURSIVE traverse({pk_name}, depth) AS (
52-
SELECT first.parent_{pk_name}, 1
52+
SELECT first.parent_id, 1
5353
FROM {relationship_table} AS first
5454
LEFT OUTER JOIN {relationship_table} AS second
55-
ON first.parent_{pk_name} = second.child_{pk_name}
56-
WHERE first.child_{pk_name} = %(pk)s
55+
ON first.parent_id = second.child_id
56+
WHERE first.child_id = %(pk)s
5757
-- LIMITING_FK_EDGES_CLAUSE_1
5858
-- DISALLOWED_ANCESTORS_NODES_CLAUSE_1
5959
-- ALLOWED_ANCESTORS_NODES_CLAUSE_1
6060
{ancestors_clauses_1}
6161
UNION
62-
SELECT DISTINCT parent_{pk_name}, traverse.depth + 1
62+
SELECT DISTINCT parent_id, traverse.depth + 1
6363
FROM traverse
6464
INNER JOIN {relationship_table}
65-
ON {relationship_table}.child_{pk_name} = traverse.{pk_name}
65+
ON {relationship_table}.child_id = traverse.{pk_name}
6666
WHERE 1 = 1
6767
-- LIMITING_FK_EDGES_CLAUSE_2
6868
-- DISALLOWED_ANCESTORS_NODES_CLAUSE_2
@@ -77,20 +77,20 @@
7777

7878
DESCENDANTS_QUERY = """
7979
WITH RECURSIVE traverse({pk_name}, depth) AS (
80-
SELECT first.child_{pk_name}, 1
80+
SELECT first.child_id, 1
8181
FROM {relationship_table} AS first
8282
LEFT OUTER JOIN {relationship_table} AS second
83-
ON first.child_{pk_name} = second.parent_{pk_name}
84-
WHERE first.parent_{pk_name} = %(pk)s
83+
ON first.child_id = second.parent_id
84+
WHERE first.parent_id = %(pk)s
8585
-- LIMITING_FK_EDGES_CLAUSE_1
8686
-- DISALLOWED_DESCENDANTS_NODES_CLAUSE_1
8787
-- ALLOWED_DESCENDANTS_NODES_CLAUSE_1
8888
{descendants_clauses_1}
8989
UNION
90-
SELECT DISTINCT child_{pk_name}, traverse.depth + 1
90+
SELECT DISTINCT child_id, traverse.depth + 1
9191
FROM traverse
9292
INNER JOIN {relationship_table}
93-
ON {relationship_table}.parent_{pk_name} = traverse.{pk_name}
93+
ON {relationship_table}.parent_id = traverse.{pk_name}
9494
WHERE 1=1
9595
-- LIMITING_FK_EDGES_CLAUSE_2
9696
-- DISALLOWED_DESCENDANTS_NODES_CLAUSE_2
@@ -104,41 +104,41 @@
104104
"""
105105

106106
PATH_LIMITING_FK_EDGES_CLAUSE = (
107-
"""AND first.{fk_field_name}_{pk_name} = %(limiting_fk_edges_instance_pk)s"""
107+
"""AND first.{fk_field_name}_id = %(limiting_fk_edges_instance_pk)s"""
108108
)
109109
PATH_LIMITING_FK_NODES_CLAUSE = """"""
110110

111111
DISALLOWED_UPWARD_PATH_NODES_CLAUSE = (
112-
"""AND second.parent_{pk_name} <> ALL('{disallowed_path_node_pks}')"""
112+
"""AND second.parent_id <> ALL('{disallowed_path_node_pks}')"""
113113
)
114114
DISALLOWED_DOWNWARD_PATH_NODES_CLAUSE = (
115-
"""AND second.child_{pk_name} <> ALL('{disallowed_path_node_pks}')"""
115+
"""AND second.child_id <> ALL('{disallowed_path_node_pks}')"""
116116
)
117117
ALLOWED_UPWARD_PATH_NODES_CLAUSE = (
118-
"""AND second.parent_{pk_name} = ALL('{allowed_path_node_pks}')"""
118+
"""AND second.parent_id = ALL('{allowed_path_node_pks}')"""
119119
)
120120
ALLOWED_DOWNWARD_PATH_NODES_CLAUSE = (
121-
"""AND second.child_{pk_name} = ALL('{allowed_path_node_pks}')"""
121+
"""AND second.child_id = ALL('{allowed_path_node_pks}')"""
122122
)
123123

124124
UPWARD_PATH_QUERY = """
125-
WITH RECURSIVE traverse(child_{pk_name}, parent_{pk_name}, depth, path) AS (
125+
WITH RECURSIVE traverse(child_id, parent_id, depth, path) AS (
126126
SELECT
127-
first.child_{pk_name},
128-
first.parent_{pk_name},
127+
first.child_id,
128+
first.parent_id,
129129
1 AS depth,
130-
ARRAY[first.child_{pk_name}] AS path
130+
ARRAY[first.child_id] AS path
131131
FROM {relationship_table} AS first
132-
WHERE child_{pk_name} = %(starting_node)s
132+
WHERE child_id = %(starting_node)s
133133
UNION ALL
134134
SELECT
135-
first.child_{pk_name},
136-
first.parent_{pk_name},
135+
first.child_id,
136+
first.parent_id,
137137
second.depth + 1 AS depth,
138-
path || first.child_{pk_name} AS path
138+
path || first.child_id AS path
139139
FROM {relationship_table} AS first, traverse AS second
140-
WHERE first.child_{pk_name} = second.parent_{pk_name}
141-
AND (first.child_{pk_name} <> ALL(second.path))
140+
WHERE first.child_id = second.parent_id
141+
AND (first.child_id <> ALL(second.path))
142142
-- PATH_LIMITING_FK_EDGES_CLAUSE
143143
-- DISALLOWED_UPWARD_PATH_NODES_CLAUSE
144144
-- ALLOWED_UPWARD_PATH_NODES_CLAUSE
@@ -150,30 +150,30 @@
150150
FROM
151151
(
152152
SELECT path || ARRAY[%(ending_node)s], depth FROM traverse
153-
WHERE parent_{pk_name} = %(ending_node)s
153+
WHERE parent_id = %(ending_node)s
154154
AND depth <= %(max_depth)s
155155
LIMIT 1
156156
) AS x({pk_name});
157157
"""
158158

159159
DOWNWARD_PATH_QUERY = """
160-
WITH RECURSIVE traverse(parent_{pk_name}, child_{pk_name}, depth, path) AS (
160+
WITH RECURSIVE traverse(parent_id, child_id, depth, path) AS (
161161
SELECT
162-
first.parent_{pk_name},
163-
first.child_{pk_name},
162+
first.parent_id,
163+
first.child_id,
164164
1 AS depth,
165-
ARRAY[first.parent_{pk_name}] AS path
165+
ARRAY[first.parent_id] AS path
166166
FROM {relationship_table} AS first
167-
WHERE parent_{pk_name} = %(starting_node)s
167+
WHERE parent_id = %(starting_node)s
168168
UNION ALL
169169
SELECT
170-
first.parent_{pk_name},
171-
first.child_{pk_name},
170+
first.parent_id,
171+
first.child_id,
172172
second.depth + 1 AS depth,
173-
path || first.parent_{pk_name} AS path
173+
path || first.parent_id AS path
174174
FROM {relationship_table} AS first, traverse AS second
175-
WHERE first.parent_{pk_name} = second.child_{pk_name}
176-
AND (first.parent_{pk_name} <> ALL(second.path))
175+
WHERE first.parent_id = second.child_id
176+
AND (first.parent_id <> ALL(second.path))
177177
-- PATH_LIMITING_FK_EDGES_CLAUSE
178178
-- DISALLOWED_DOWNWARD_PATH_NODES_CLAUSE
179179
-- ALLOWED_DOWNWARD_PATH_NODES_CLAUSE
@@ -185,7 +185,7 @@
185185
FROM
186186
(
187187
SELECT path || ARRAY[%(ending_node)s], depth FROM traverse
188-
WHERE child_{pk_name} = %(ending_node)s
188+
WHERE child_id = %(ending_node)s
189189
AND depth <= %(max_depth)s
190190
LIMIT 1
191191
) AS x({pk_name});

0 commit comments

Comments
 (0)