From: Mike Bayer Date: Fri, 10 Nov 2006 15:57:58 +0000 (+0000) Subject: fix to query.count to use mapper-defined primary key cols instead of those of the... X-Git-Tag: rel_0_3_1~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2466dca12d39643fc8531b7b8807a9850c3a3f9d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix to query.count to use mapper-defined primary key cols instead of those of the table --- diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 208c7372b8..6c978f3620 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -267,7 +267,8 @@ class Query(object): if self._nestable(**kwargs): s = sql.select([self.table], whereclause, **kwargs).alias('getcount').count() else: - s = sql.select([sql.func.count(list(self.table.primary_key)[0])], whereclause, from_obj=from_obj, **kwargs) + primary_key = self.mapper.pks_by_table[self.table] + s = sql.select([sql.func.count(list(primary_key)[0])], whereclause, from_obj=from_obj, **kwargs) return self.session.scalar(self.mapper, s, params=params) def select_statement(self, statement, **params):