This commit is contained in:
Maxime Rainville 2024-03-21 05:30:34 +13:00 committed by GitHub
commit 60a559a5a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View File

@ -96,4 +96,8 @@ class DBBoolean extends DBField
}
return $value ? 1 : 0;
}
public function RAW() {
return $this->prepValueForDB($this->getValue());
}
}

View File

@ -53,7 +53,7 @@ class ExactMatchFilter extends SearchFilter
{
$this->model = $query->applyRelation($this->relation);
$field = $this->getDbName();
$value = $this->getValue();
$value = $this->getDbFormattedValue();
// Null comparison check
if ($value === null) {
@ -77,7 +77,7 @@ class ExactMatchFilter extends SearchFilter
}
$clause = [$where => $value];
return $this->aggregate ?
$this->applyAggregate($query, $clause) :
$query->where($clause);

View File

@ -801,6 +801,20 @@ class DataListTest extends SapphireTest
$this->assertEquals(0, $list->count());
}
public function testFilterByBoolean() {
$list = Player::get();
$list = $list->filter(['IsRetired' => false]);
$this->assertEquals(3, $list->count(), 'Some records have IsRetired set to false');
$allFalse = $list->column('IsRetired');
$this->assertNotContains(true, $allFalse, 'Filter false should filter all true values');
$list = Player::get();
$list = $list->filter(['IsRetired' => true]);
$this->assertEquals(1, $list->count(), 'One records has IsRetired set to true');
$allTrue = $list->column('IsRetired');
$this->assertNotContains(false, $allTrue, 'Filter true should filter all false values');
}
/**
* $list->filter(['Name'=>'bob, 'Age'=>21]); // bob with the age 21
*/