group() public méthode

Create a GROUP BY SQL clause.
public group ( string | array $fields, Model $Model = null ) : string
$fields string | array Group By fields
$Model Model The model to get group by fields for.
Résultat string Group By clause or null.
 /**
  * test group to generate GROUP BY statements on virtual fields
  *
  * @return void
  */
 public function testVirtualFieldsInGroup()
 {
     $Article = ClassRegistry::init('Article');
     $Article->virtualFields = array('this_year' => 'YEAR(Article.created)');
     $result = $this->Dbo->group('this_year', $Article);
     $expected = " GROUP BY (YEAR(`Article`.`created`))";
     $this->assertEquals($expected, $result);
 }
Exemple #2
0
 /**
  * test group to generate GROUP BY statements on virtual fields
  *
  * @return void
  */
 public function testVirtualFieldsInGroup()
 {
     $Boat = ClassRegistry::init('Boat');
     $Boat->virtualFields = array('this_year' => 'YEAR(Boat.created)');
     $result = $this->Dbo->group('this_year', $Boat);
     $expected = " GROUP BY (YEAR(`Boat`.`created`))";
     $this->assertEquals($expected, $result);
 }