Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ensure boolean values are converted to correct value on update, avoid…

…ing issues with posgres boolean type
  • Loading branch information...
commit 091ad53b8009a44ecb58798510d20a0f7f8078e2 1 parent c38419e
@ceeram ceeram authored
View
2  lib/Cake/Model/Datasource/DboSource.php
@@ -1836,6 +1836,8 @@ protected function _prepareUpdateFields(Model $model, $fields, $quoteValues = tr
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
View
48 lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -6605,4 +6605,52 @@ public function testSaveAllDeepHasManyBelongsTo() {
$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']);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.