Re: [SQLObject] _defaultOrder with Joins: bug?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2003-04-10 04:52:57
|
On Wed, 2003-04-09 at 20:28, Luke Opperman wrote: > Yep, I never submitted my (possibly ugly) patch for this > from when I made the suggestion. Here's the sticky part: > SQLObject's join's don't actually do an SQL JOIN, they just > get Ids. Again based on my familiarity with MySQL, which doesn't have real foreign keys. If you can suggest the changes, to the SQL in particular, that would be good. Well, I should probably just read up on it, since I'm starting to use Postgres more myself. > So there's no easy way to just add an "ORDER BY" > clause into the SQL code. It's going to come down to speed > one way or another, so it may be worthwhile to make them do > full JOINs, but here's the fix for the least amount of code > change: Just sort the list of objects after you instantiate > them. In each Join's performJoin function, > > return [cls(id) for (id,) in ids] > > becomes > > objs = [cls(id) for (id,) in ids] > if cls._defaultOrder: > order = cls._defaultOrder > objs.sort(lambda x,y: cmp(getattr(x, order), > getattr(y, order))) > return objs Really this should be changed to do a more complete SELECT, as I'm doing with .select results (it fetches not just IDs, but also column values). This code precedes that change. Once you are fetching the entire object, it should be relatively easy to do ORDER BY in the SQL, rather than after the fact. Ian |