BUG Nomalise boolean ORM filter in to 1/0

This commit is contained in:
Maxime Rainville 2021-02-16 23:53:57 +13:00
parent 15c0621fb6
commit 906d426034
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) {

View File

@ -793,6 +793,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
*/