From b82aca081c165036d8fd25b902b013fae15313e1 Mon Sep 17 00:00:00 2001 From: limodou Date: Mon, 10 Oct 2016 18:37:33 +0800 Subject: [PATCH] Add keep_primary_key parameter to fields() of ORM --- uliweb/orm/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uliweb/orm/__init__.py b/uliweb/orm/__init__.py index 835a96d..3772794 100644 --- a/uliweb/orm/__init__.py +++ b/uliweb/orm/__init__.py @@ -2599,11 +2599,11 @@ def having(self, *args): self._having = args return self - def fields(self, *args, **kwargs): + def fields(self, keep_primary_key=True, *args, **kwargs): if args: args = flat_list(args) if args: - if self.model._primary_field and self.model._primary_field not in args: + if keep_primary_key and self.model._primary_field and self.model._primary_field not in args: args.append(self.model._primary_field) self.funcs.append(('with_only_columns', ([self.get_column(self.model, x) for x in args],), kwargs)) return self @@ -3042,11 +3042,11 @@ def has(self, *objs): (self.table.c[self.fieldb].in_(keys))).limit(1)) return len(list(row)) > 0 - def fields(self, *args, **kwargs): + def fields(self, keep_primary_key=True, *args, **kwargs): if args: args = flat_list(args) if args: - if self.modelb._primary_field and self.modelb._primary_field not in args: + if keep_primary_key and self.modelb._primary_field and self.modelb._primary_field not in args: args.append(self.modelb.c[self.modelb._primary_field]) self.funcs.append(('with_only_columns', ([self.get_column(self.modelb, x) for x in args],), kwargs)) return self