The bad news with "results = meta.Session.execute(s).fetchall()" is that it runs for every page in the paginator, fetching all rows each time.
Thoughts, anyone? On Jun 19, 12:17 pm, Hollister <a.hollister.willi...@gmail.com> wrote: > Update: > > If I run: > results = meta.Session.execute(s).fetchall() > and pass that to paginate, it works. > > I guess I just needed the ResultProxy, and not a collection of mapped > objects. > > Mike, if you have any additional insight for me, I would appreciate > it. > > On Jun 19, 11:30 am, Hollister <a.hollister.willi...@gmail.com> wrote: > > > I have a simple query with a group_by and count(), and I'd like to > > pass this to webhelpers.paginate for display: > > > def referrers(self): > > s = select([m.hit_table.c.id, m.hit_table.c.referer, func.count > > (m.Hit.referer).label('count')], > > from_obj = [m.hit_table], > > group_by = [m.Hit.referer], > > order_by = 'count desc') > > > query = meta.Session.query(m.Hit).from_statement(s) > > > c.paginator = paginate.Page( > > query, > > page = int(request.params.get('page', 1)), > > items_per_page = 50, > > ) > > return render('/derived/hits/referrer_list.html') > > > The sql generated by this is fine: > > > SELECT hit.id AS hit_id, hit.referer AS hit_referer, count > > (hit.referer) AS count > > FROM hit GROUP BY hit.referer ORDER BY count desc > > > and the results are correct. > > > When I run this, I get: > > > Module sqlalchemy.orm.query:1956 in setup_context > > << context.froms.append(self.selectable) > > if context.order_by is False and self.mapper.order_by: > > context.order_by = self.mapper.order_by>> if > > context.order_by is False and self.mapper.order_by: > > > AttributeError: 'QueryContext' object has no attribute 'order_by' > > > This evidently has nothing to do with the query's order_by clause > > since I get the same error if I remove it. If I execute the query and > > pass the results to paginate: > > > results = query.all() > > > c.paginator = paginate.Page( > > results, > > page = int(request.params.get('page', 1)), > > items_per_page = 50, > > ) > > > I get: > > > AttributeError: 'Hit' object has no attribute 'count' > > > Which I guess makes sense, since I don't have that defined in my > > class. > > > What am I doing wrong? > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---