From 6210a606119b3f2a2eeb057b372633fdc353771c Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 2 Oct 2006 20:51:36 +0000 Subject: [PATCH] Fixed a bug when saving a record with null valued boolean column --- lib/Doctrine/Record.php | 11 +++++----- tests/BooleanTestCase.php | 44 +++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 127233f84..70a8143b1 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -862,6 +862,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite foreach($array as $k => $v) { $type = $this->table->getTypeOf($v); + + if($this->data[$v] === self::$null) { + $a[$v] = null; + continue; + } switch($type) { case 'array': @@ -881,11 +886,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite if($this->data[$v] instanceof Doctrine_Record) $this->data[$v] = $this->data[$v]->getIncremented(); - - if($this->data[$v] === self::$null) - $a[$v] = null; - else - $a[$v] = $this->data[$v]; + $a[$v] = $this->data[$v]; } } diff --git a/tests/BooleanTestCase.php b/tests/BooleanTestCase.php index f9a49df1b..caef1fa43 100644 --- a/tests/BooleanTestCase.php +++ b/tests/BooleanTestCase.php @@ -5,28 +5,6 @@ class Doctrine_BooleanTestCase extends Doctrine_UnitTestCase { $this->tables = array("BooleanTest"); parent::prepareTables(); } - - public function testSetNull() { - $test = new BooleanTest(); - $this->is_working = null; - - $this->assertEqual($this->is_working, null); - $this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY); - $test->save(); - - $test->refresh(); - $this->assertEqual($test->is_working, null); - - $test = new BooleanTest(); - $this->is_working_notnull = null; - - $this->assertEqual($this->is_working_notnull, false); - $this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY); - $test->save(); - - $test->refresh(); - $this->assertEqual($test->is_working_notnull, false); - } public function testSetFalse() { $test = new BooleanTest(); @@ -84,5 +62,27 @@ class Doctrine_BooleanTestCase extends Doctrine_UnitTestCase { $this->assertEqual(count($ret), 1); } + public function testSavingNullValue() { + $test = new BooleanTest(); + $this->is_working = null; + + $this->assertEqual($this->is_working, null); + $this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY); + $test->save(); + + $test->refresh(); + $this->assertEqual($test->is_working, null); + + $test = new BooleanTest(); + $this->is_working_notnull = null; + + $this->assertEqual($this->is_working_notnull, false); + $this->assertEqual($test->getState(), Doctrine_Record::STATE_TDIRTY); + $test->save(); + + $test->refresh(); + $this->assertEqual($test->is_working_notnull, false); + } + } ?>