#9368: Clean up code for getting columns for select query
------------------------------------------+---------------------------------
 Reporter:  adunar                        |       Owner:  nobody    
   Status:  new                           |   Milestone:  post-1.0  
Component:  Database layer (models, ORM)  |     Version:            
 Keywords:                                |       Stage:  Unreviewed
Has_patch:  1                             |  
------------------------------------------+---------------------------------
 I cleaned up some code in db/models/sql/query.py (see mtredinnick's
 suggestion on http://code.djangoproject.com/ticket/5420)

 In particular:
  * The code to get a column's SQL alias was duplicated in 6 places, so I
 factored that out into a function
  * Depending on whether the get_default_columns function was called for
 the base model or a related model, it took different parameters, did
 different things, and returned different values. So I split it into two
 separate functions, get_base_columns and get_related_columns. This
 refactoring makes the Query class easier to understand and easier to
 subclass with less code duplication.
  * I added a function Query.get_base_fields, which the !QuerySet class
 uses to determine which fields correspond to the values from the result
 set. Currently, get_base_fields returns all fields of the base model.
 However, Query subclasses could potentially override get_base_fields (as
 well as get_base_columns) so that only a subset of the model's fields are
 returned (e.g. if you want to lazy-load some large fields).

 A large motivation for this refactoring is that functional decomposition
 of get_columns made it difficult to subclass Query to provide custom
 behavior. This can be seen especially well in contrib.gis.db.models.query,
 where it needed to override a small bit of logic in the middle of
 get_columns and get_default_columns, but ended up having to copy and paste
 those entire functions (which were both quite large) as a result. My
 change at least makes it so gis doesn't have to copy and paste quite as
 much. I would have liked to not copy and paste anything in gis, but I
 didn't quite figure out how to do that without breaking the regression
 tests. (Also, I haven't even run the code in gis because I don't have the
 necessary libraries installed. So somebody else might want to test that
 part...)

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9368>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to