Closed akunerio closed 1 year ago
The distinct function in hydrahon does not create a distinct function around a field but rather marks the entire select statement as distinct.
This is also why the distinct function does not accept a field argument. See the implementation:
/**
* Distinct select setter
*
* @param bool $distinct
* @return static The current query builder.
*/
public function distinct($distinct = true)
{
$this->distinct = $distinct; return $this;
}
So the difference is:
use ClanCats\Hydrahon\Query\Expression;
// select distinct * from foo
$h->table('foo')->select()->distinct();
// select distinct(column_name) from foo
$h->table('foo')->select([new Expression('DISTINCT(colum_name)')]);
->distinct('column_name')
It will have different result from
->addField(new \ClanCats\Hydrahon\Query\Expression('DISTINCT(colum_name)'))
I use the second one. I think the result need to be same, right?