Using GROUP_CONCAT in a Model


#1

Hello Guys!

I am trying to figure out a way to use GROUP_CONCAT in a model

 $this->hasMany('OrderItems', new OrderItem())
    ->addFields(
        [
            ['items', 'aggregate' => 'group_concat', 'field' => 'name', 'type' => 'string']
        ]
    );

But I have 2 problems:

  1. I cannot set a SEPARATOR and the second one is that if field is empty;
  2. I get a ‘0’ when there is no data, instead of an empty string like this: https://www.screencast.com/t/w9819w4QHD

#2

i have created PR to address this.


#3

This works great and solves both of the problems.

Thank you Romans!