I'm working with getting a GROUP_CONCAT field into views for my module and I've been using this post as a guide: http://drupal.stackexchange.com/a/12364/2735

I'm almost there, having successfully added the groupby to a new field in _view_query_alter. The problem I'm having is getting that field out into views, so that it's an option in the "Fields" area of the views UI. In the SQL, according to Views, I've correctly got the GROUP BY and the GROUP_CONCAT, where the concat in the SELECT looks something like:

GROUP_CONCAT(month_id) AS months
However, when I try to get 'months' back out in _views_data, it either (a) adds the table name to 'months' as in:

SELECT mytable.field1,
mytable.months ...

or (b) does not recognize the field at all in the Views UI.

In _views_data, I try defining the field with:

$data['mytable']['months']
which produces (a), and with:

$data['']['months']
which produces (b). I know I'm missing something small here. Can anyone tell me what it is?

Comments

robynover’s picture

Title: Access a grouped field set in hook_views_query_alter » Access a grouped field that was set in hook_views_query_alter
robynover’s picture

Component: Views Data » Miscellaneous
robynover’s picture

Solved. I put the query info into a field handler instead of in views_query_alter.

dawehner’s picture

Status: Active » Fixed

Cool, let's mark it as well.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.