user1323512
user1323512

Reputation: 137

PHP Propel groupBy two columns

I have a problem with groupBy in propel:

The problem belongs to two tables. One is called displays and the other is called customerDisplayType. In the customerDisplayType-table there are two columns 'driver' and 'driverOptions'. And I want to groupBy on this two columns. So that the result could look like this:

Display1 -> with customerDisplayType driver "1" and driverOptions "xyz"
Display2 -> with customerDisplayType driver "1" and driverOptions "abc"
Display3 -> with customerDisplayType driver "2" and driverOptions "xyz"

I hope you know what I mean...

So far, I tried something like this:

    $displays = PiDisplayQuery::create()
    ->filterByStationId($_object->getId())    
    ->usePiCustomerDisplayTypeQuery()
        ->groupBy("CONCAT ".PiCustomerDisplayTypePeer::DRIVER.",".PiCustomerDisplayTypePeer::DRIVER_OPTIONS) // I also tried UNION instead of CONCAT
    ->endUse()
    ->find();

How can I solve it?

Upvotes: 2

Views: 1099

Answers (1)

j0k
j0k

Reputation: 22756

Regarding the code, if you want to use more than one groupBy, you just have to call groupBy method several times:

$displays = PiDisplayQuery::create()
  ->filterByStationId($_object->getId())
  ->usePiCustomerDisplayTypeQuery()
    ->groupBy('PiCustomerDisplayType.Driver')
    ->groupBy('PiCustomerDisplayType.DriverOptions')
  ->endUse()
  ->find();

Upvotes: 2

Related Questions