mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-08 10:41:25 +02:00
Merge pull request #2242 from torleif/3.0
FIX postgres can filter on non text fields
This commit is contained in:
commit
dd801bdb0b
@ -16,13 +16,14 @@ class PartialMatchFilter extends SearchFilter {
|
|||||||
$this->model = $query->applyRelation($this->relation);
|
$this->model = $query->applyRelation($this->relation);
|
||||||
$where = array();
|
$where = array();
|
||||||
$comparison = (DB::getConn() instanceof PostgreSQLDatabase) ? 'ILIKE' : 'LIKE';
|
$comparison = (DB::getConn() instanceof PostgreSQLDatabase) ? 'ILIKE' : 'LIKE';
|
||||||
|
$dbname = (DB::getConn() instanceof PostgreSQLDatabase) ? $this->getDbName().'::text' : $this->getDbName();
|
||||||
if(is_array($this->getValue())) {
|
if(is_array($this->getValue())) {
|
||||||
foreach($this->getValue() as $value) {
|
foreach($this->getValue() as $value) {
|
||||||
$where[]= sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($value));
|
$where[]= sprintf("%s %s '%%%s%%'", $dbname, $comparison, Convert::raw2sql($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$where[] = sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($this->getValue()));
|
$where[] = sprintf("%s %s '%%%s%%'", $dbname, $comparison, Convert::raw2sql($this->getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query->where(implode(' OR ', $where));
|
return $query->where(implode(' OR ', $where));
|
||||||
|
Loading…
Reference in New Issue
Block a user