mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
ensure boolean values are converted to correct value on update, avoiding issues with posgres boolean type
This commit is contained in:
parent
c38419e33a
commit
091ad53b80
2 changed files with 50 additions and 0 deletions
|
@ -1836,6 +1836,8 @@ class DboSource extends DataSource {
|
|||
|
||||
if ($quoteValues) {
|
||||
$update .= $this->value($value, $model->getColumnType($field));
|
||||
} elseif ($model->getColumnType($field) == 'boolean') {
|
||||
$update .= $this->boolean($value, true);
|
||||
} elseif (!$alias) {
|
||||
$update .= str_replace($quotedAlias . '.', '', str_replace(
|
||||
$model->alias . '.', '', $value
|
||||
|
|
|
@ -6605,4 +6605,52 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testUpdateAllBoolean
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function testUpdateAllBoolean() {
|
||||
$this->loadFixtures('Item', 'Syfile', 'Portfolio', 'Image', 'ItemsPortfolio');
|
||||
$TestModel = new Item();
|
||||
$result = $TestModel->updateAll(array('published' => true));
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $TestModel->find('first', array('fields' => array('id', 'published')));
|
||||
$this->assertEquals(true, $result['Item']['published']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testUpdateAllBooleanConditions
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function testUpdateAllBooleanConditions() {
|
||||
$this->loadFixtures('Item', 'Syfile', 'Portfolio', 'Image', 'ItemsPortfolio');
|
||||
$TestModel = new Item();
|
||||
|
||||
$result = $TestModel->updateAll(array('published' => true), array('Item.id' => 1));
|
||||
$this->assertTrue($result);
|
||||
$result = $TestModel->find('first', array(
|
||||
'fields' => array('id', 'published'),
|
||||
'conditions' => array('Item.id' => 1)));
|
||||
$this->assertEquals(true, $result['Item']['published']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testUpdateBoolean
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function testUpdateBoolean() {
|
||||
$this->loadFixtures('Item', 'Syfile', 'Portfolio', 'Image', 'ItemsPortfolio');
|
||||
$TestModel = new Item();
|
||||
|
||||
$result = $TestModel->save(array('published' => true, 'id' => 1));
|
||||
$this->assertTrue((boolean)$result);
|
||||
$result = $TestModel->find('first', array(
|
||||
'fields' => array('id', 'published'),
|
||||
'conditions' => array('Item.id' => 1)));
|
||||
$this->assertEquals(true, $result['Item']['published']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue