"dds" <[EMAIL PROTECTED]> writes: > Hi Christoph, > > Thanks for looking into the pagination stuff. > > On Jan 29, 11:54 pm, Christoph Haas <e...-Nf+wZpSdgwd6//[EMAIL PROTECTED]> > wrote: > >> The documentation >> athttp://pylonshq.com/WebHelpers/module-webhelpers.pagination.htmlcontains >> this example: >> >> # In this case, Person is a SQLObject class, or it could be a list/tuple >> person_paginator, person_set = paginate(Person, page=1) >> >> It wasn't very clear to me how that is supposed to work with SQLAlchemy. It >> must look like this: >> >> person_paginator, person_set = \ >> h.pagination.paginate(model.Person.select()) >> >> Can we please add that example to the the webhelpers/pagination/orm.py >> module? >> > > But this is exactly what the paginator is supposed to avoid when using > an ORM. You're selecting every person from the database, pulling it > into memory, and making the paginator chunk it up. The point of giving > it a real query object is that it should use limit and offset to > select only the elements from the DB to make the current page, not > carry it all around in memory. > > I started a ticket for using the paginator with assign_mapper (in > broken English) about a month ago. See #167. >
I've updated the ticket with a link to a trivial patch so that you can do person_paginator, person_set = h.pagination.paginate(model.Person, page=0) which is how it should work, correct? The patch makes the paginator check if the object has count and select methods instead of whether it is an SQLAlchemy Query or Mapper object, thus it works with mapper assigned classes and with Query objects directly (the old method nor the patch work with mapper objects, nor should they). I'd rather see tests and/or examples for how the paginator can be reused between requests (or if that's inappropriate, what exactly the paginator is good for compared to doing it 'manually'). If you have a moment, give the patch a try. Thanks, -- David D. Smith
pgpK9gO4ndvaL.pgp
Description: PGP signature
