summaryrefslogtreecommitdiff
path: root/archivist/peewee_fixes.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2017-03-12 13:42:28 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2017-03-12 13:42:28 +0100
commit55a9927413f826d3d9dfb68a058d59163f94a8ca (patch)
treeff36ed38f0f0dcba6caa398d622553ae4bba23cd /archivist/peewee_fixes.py
parent01a80c04fa72da63e6cd4f1973d299479fbe5566 (diff)
downloadarchivist-55a9927413f826d3d9dfb68a058d59163f94a8ca.tar.gz
archivist-55a9927413f826d3d9dfb68a058d59163f94a8ca.tar.bz2
archivist-55a9927413f826d3d9dfb68a058d59163f94a8ca.zip
Fix handling of composite pks in peewee.
Diffstat (limited to 'archivist/peewee_fixes.py')
-rw-r--r--archivist/peewee_fixes.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/archivist/peewee_fixes.py b/archivist/peewee_fixes.py
new file mode 100644
index 0000000..ff914da
--- /dev/null
+++ b/archivist/peewee_fixes.py
@@ -0,0 +1,15 @@
+from peewee import QueryCompiler, strip_parens, ForeignKeyField
+
+__all__ = []
+
+def _parse_select_query(self, node, alias_map, conv):
+ clone = node.clone()
+ if not node._explicit_selection:
+ if conv and isinstance(conv, ForeignKeyField):
+ clone._select = (conv.to_field,)
+ else:
+ clone._select = clone.model_class._meta.get_primary_key_fields()
+ sub, params = self.generate_select(clone, alias_map)
+ return '(%s)' % strip_parens(sub), params
+
+QueryCompiler._parse_select_query = _parse_select_query