Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG Nomalise boolean ORM filter in to 1/0 #9865

Draft
wants to merge 1 commit into
base: 4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ORM/FieldType/DBBoolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ public function prepValueForDB($value)
}
return $value ? 1 : 0;
}

public function RAW() {
return $this->prepValueForDB($this->getValue());
}
}
4 changes: 2 additions & 2 deletions src/ORM/Filters/ExactMatchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function oneFilter(DataQuery $query, $inclusive)
{
$this->model = $query->applyRelation($this->relation);
$field = $this->getDbName();
$value = $this->getValue();
$value = $this->getDbFormattedValue();

// Null comparison check
if ($value === null) {
Expand All @@ -77,7 +77,7 @@ protected function oneFilter(DataQuery $query, $inclusive)
}

$clause = [$where => $value];

return $this->aggregate ?
$this->applyAggregate($query, $clause) :
$query->where($clause);
Expand Down
14 changes: 14 additions & 0 deletions tests/php/ORM/DataListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,20 @@ public function testMultipleFilterWithNoMatch()
$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
*/
Expand Down