Skip to content

Commit

Permalink
Merge pull request #25 from Edilton/master
Browse files Browse the repository at this point in the history
Bug fix in group by with joins
  • Loading branch information
nicolaslopezj committed Feb 4, 2015
2 parents be19950 + 122eb21 commit 2351c81
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/SearchableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,25 @@ protected function makeJoins(&$query)
protected function makeGroupBy(&$query)
{
$driver = $this->getDatabaseDriver();

if ($driver == 'sqlsrv') {
$columns = $this->getTableColumns();
} else {
$columns = $this->primaryKey;
}
$id = $this->getTable() . '.' .$this->primaryKey;
$joins = array_keys(($this->getJoins()));

foreach ($this->getColumns() as $column => $relevance) {

array_map(function($join) use ($column, $query){

$query->groupBy($columns);
if(Str::contains($column, $join)){
$query->groupBy("$column");
}

}, $joins);

}
}
$query->groupBy($id);
}

/**
Expand Down

0 comments on commit 2351c81

Please sign in to comment.