I have a view that is using a format that doesn't include group by fields in its settings. I'm trying to mimic that by using the hook_views_query_alter()
function in a module.
I know the code is running, because I see the DPM value and the error log string, but the group by doesn't seem to be working. I know that group by in views is a different thing than mySQL's group_concat (which you can use via aggregation, but that doesn't work in this case because we need one field to not be aggregated.) So I'm not expecting to see a group_concat in the printed-out query. But I would have expected it to produce the same results as if I had set up Group By in unformatted list settings for the same four fields (which does work as expected.)
Here is what my view looks like without any group-by (either in the settings or the module):
You can see that there are two complete chunks of information for April Carlisle, because she is speaking at two sessions.
If I turn on Group By for speaker name (content: title), job title, and company in unformatted list settings, this is what I get (and what I want):
So I had thought that my module code would reproduce that result, but it's not. Can anyone tell me why?
Here's the main function:
function group_speaker_carousel_views_query_alter(&$view, &$query) {
switch($view->name) {
case 'speakers_carousel':
error_log("view name now: ".$view->name);
$query->groupby[0]['field'] = "title";
$query->groupby[1]['field'] = "field_job_title";
$query->groupby[2]['field'] = "field_company";
$select_query = $query->query();
$query_string = (string)$select_query;
dpm($query_string);
break;
}
}