nicolaslopezj / searchable

A php trait to search laravel models
MIT License
2.01k stars 291 forks source link

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'k_k_people.NameHindi' in 'group statement' #201

Open sandeeprawat88 opened 5 years ago

sandeeprawat88 commented 5 years ago

This issue came when this library creating multiple group by and if db has $prefix then it append two times because getColumns() calls twice in SearchableTrait First in scopeSearchRestricted() function and secondly in makeGroupBy() functions

I found a solution that we need to replace code from line 209 to 2016 with below code $prefix = Config::get("database.connections.$driver.prefix"); foreach ($this->getColumns() as $column => $relevance) { array_map(function ($join) use ($column, $query, $prefix) { if (Str::contains($column, $join)) { $column = str_replace($prefix, "", $column); $query->groupBy($column); } }, $joins); }

This resolves the issue. @nicolaslopezj can you please make these changes to the library