Skip to content

Commit

Permalink
Merge pull request #110 from darthtaco/5.2
Browse files Browse the repository at this point in the history
Enable searchable on SQLServer based models
  • Loading branch information
jarektkaczyk committed Aug 25, 2016
2 parents f4a0b20 + e33f55c commit 91d1dc6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,22 @@ protected function buildSubquery(array $words, array $mappings, $threshold)
? array_sum($columns->getWeights()) / 4
: (float) $threshold;

$modelTableName = $this->model->getTable();

// If we are dealing with a SQL Server database, we need to group by all column names
if ( $this->model->getConnection()->getDriverName() == 'sqlsrv' ) {
$groupByColumns = $this->model->getConnection()->getSchemaBuilder()->getColumnListing($modelTableName);
// Force column names to be fully-qualified
foreach ($groupByColumns as &$column) {
$column = $modelTableName . '.' . $column;
}
} else {
$groupByColumns = $this->model->getQualifiedKeyName();
}

$subquery->select($this->model->getTable() . '.*')
->from($this->model->getTable())
->groupBy($this->model->getQualifiedKeyName());
->groupBy($groupByColumns);

$this->addSearchClauses($subquery, $columns, $words, $threshold);

Expand Down

0 comments on commit 91d1dc6

Please sign in to comment.