Opened 14 years ago

Closed 14 years ago

#14657 closed (invalid)

Extra select fields are merged into 'GROUP BY'

Reported by: Gregory Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Keywords: extra_select,
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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`

Attachments (1)

extra_select.diff (735 bytes ) - added by Gregory 14 years ago.

Download all attachments as: .zip

Change History (2)

by Gregory, 14 years ago

Attachment: extra_select.diff added

comment:1 by Russell Keith-Magee, 14 years ago

milestone: 1.3
Resolution: invalid
Status: newclosed

qs.query.group_by (in fact, the entire qs.query structure) is an internal implementation detail. It isn't designed to be modified by end users. We don't (and won't) make any guarantees about how qs.query.group_by interacts with any other part of a query. We don't even guarantee that it will continue to exist.

Note: See TracTickets for help on using tickets.
Back to Top