- Fixes GROUP BY when using non-aggregate columns
This commit is contained in:
@ -304,14 +304,19 @@ class Subscriber extends Model {
|
||||
return $orm;
|
||||
}
|
||||
|
||||
static function filterWithCustomFieldsForExport($orm) {
|
||||
static function filterWithCustomFieldsForExport($orm, $group_by = false) {
|
||||
$orm = $orm->select(MP_SUBSCRIBERS_TABLE.'.*');
|
||||
$customFields = CustomField::findArray();
|
||||
foreach ($customFields as $customField) {
|
||||
$orm = $orm->selectExpr(
|
||||
'CASE WHEN ' .
|
||||
MP_CUSTOM_FIELDS_TABLE . '.id=' . $customField['id'] . ' THEN ' .
|
||||
MP_SUBSCRIBER_CUSTOM_FIELD_TABLE . '.value END as "' . $customField['id'].'"');
|
||||
sprintf(
|
||||
'%s CASE WHEN ' .
|
||||
MP_CUSTOM_FIELDS_TABLE . '.id=' . $customField['id'] . ' THEN ' .
|
||||
MP_SUBSCRIBER_CUSTOM_FIELD_TABLE . '.value END %s as "' . $customField['id'].'"',
|
||||
($group_by) ? 'MAX(' : '',
|
||||
($group_by) ? ')' : ''
|
||||
)
|
||||
);
|
||||
}
|
||||
$orm = $orm
|
||||
->leftOuterJoin(
|
||||
|
Reference in New Issue
Block a user