#14657: Extra select fields are merged into 'GROUP BY'
------------------------------------------+---------------------------------
 Reporter:  Gregory                       |       Owner:  nobody    
   Status:  new                           |   Milestone:  1.3       
Component:  Database layer (models, ORM)  |     Version:  1.2       
 Keywords:  extra_select,                 |       Stage:  Unreviewed
Has_patch:  1                             |  
------------------------------------------+---------------------------------
 Fields are merged into 'GROUP BY', when using some extra select fields and
 query.group_by attribute.

 {{{
         fragments = Fragment.objects.all().extra(
             select = {'au_names': 'GROUP_CONCAT(lib_author.surnames ORDER
 BY names DESC SEPARATOR ", ")'},
         )
         fragments.query.group_by = ['lib_fragment.id']
         fragments.query.join((None, 'lib_fragment', None, None))

         connection = (
             'lib_fragment',
             'lib_fragment_authors',
             'id',
             'fragment_id',
         )
         fragments.query.join(connection, promote=True)

         connection = (
             'lib_fragment_authors',
             'lib_author',
             'author_id',
             'id',
         )
         fragments.query.join(connection, promote=True)
 }}}


 {{{
 SELECT
     (GROUP_CONCAT(lib_author.surnames ORDER BY names DESC SEPARATOR ", "))
 AS `au_ids`,
 FROM `lib_fragment`
     LEFT OUTER JOIN `lib_fragment_authors` ON (`lib_fragment`.`id` =
 `lib_fragment_authors`.`fragment_id`)
     LEFT OUTER JOIN `lib_author` ON (`lib_fragment_authors`.`author_id` =
 `lib_author`.`id`)
 GROUP BY (lib_fragment.id), (GROUP_CONCAT(lib_author.surnames ORDER BY
 names DESC SEPARATOR ", "))
 ORDER BY `lib_fragment`.`id`
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14657>
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-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to