Changeset 4580
- Timestamp:
- 06/28/08 07:28:01 (6 months ago)
- Location:
- branches/0.11
- Files:
-
- 5 modified
-
lib/Doctrine/Collection.php (modified) (1 diff)
-
lib/Doctrine/Record.php (modified) (6 diffs)
-
tests/Record/FromArrayTestCase.php (modified) (1 diff)
-
tests/Record/SynchronizeTestCase.php (modified) (1 diff)
-
tests/run.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.11/lib/Doctrine/Collection.php
r4520 r4580 721 721 // create new records for each new row in the array 722 722 foreach ($array as $rowKey => $row) { 723 $this[$rowKey]-> fromArray($row);723 $this[$rowKey]->synchronizeWithArray($row); 724 724 } 725 725 } -
branches/0.11/lib/Doctrine/Record.php
r4573 r4580 914 914 { 915 915 if (isset($this->_data[$fieldName])) { 916 $type = $this->_table->getTypeOf($fieldName); 916 917 if ($value instanceof Doctrine_Record) { 917 $type = $this->_table->getTypeOf($fieldName);918 919 918 $id = $value->getIncremented(); 920 919 … … 930 929 } 931 930 932 if ($ old !== $value) {931 if ($this->_isValueModified($type, $old, $value)) { 933 932 if ($value === null) { 934 933 $value = self::$_null; … … 959 958 960 959 return $this; 960 } 961 962 /** 963 * Check if a value has changed according to Doctrine 964 * Doctrine is loose with type checking in the same ways PHP is for consistancy of behavior 965 * 966 * This function basically says if what is being set is of Doctrine type boolean and something 967 * like current_value == 1 && new_value = true would not be considered modified 968 * 969 * Simply doing $old !== $new will return false for boolean columns would mark the field as modified 970 * and change it in the database when it is not necessary 971 * 972 * @param string $type Doctrine type of the column 973 * @param string $old Old value 974 * @param string $new New value 975 * @return boolean $modified Whether or not Doctrine considers the value modified 976 */ 977 protected function _isValueModified($type, $old, $new) 978 { 979 if ($type == 'boolean' && (is_bool($old) || is_numeric($old)) && (is_bool($new) || is_numeric($new)) && $old == $new) { 980 return false; 981 } else { 982 return $old !== $new; 983 } 961 984 } 962 985 … … 1339 1362 public function fromArray($array, $deep = true) 1340 1363 { 1341 if (is_array($array)) { 1342 foreach ($array as $key => $value) { 1343 if ($deep && $this->getTable()->hasRelation($key)) { 1344 $this->$key->fromArray($value, $deep); 1345 } else if ($this->getTable()->hasField($key)) { 1346 $this->set($key, $value); 1347 } 1348 } 1349 } 1364 return $this->synchronizeWithArray($array, $deep); 1350 1365 } 1351 1366 … … 1361 1376 * @param array $array representation of a Doctrine_Record 1362 1377 */ 1363 public function synchronizeWithArray(array $array) 1364 { 1378 public function synchronizeWithArray(array $array, $deep = true) 1379 { 1380 $refresh = false; 1365 1381 foreach ($array as $key => $value) { 1366 if ($this->getTable()->hasRelation($key)) { 1382 if ($key == 'identifier') { 1383 $refresh = true; 1384 $this->assignIdentifier((array) $value); 1385 continue; 1386 } 1387 if ($deep && $this->getTable()->hasRelation($key)) { 1367 1388 $this->get($key)->synchronizeWithArray($value); 1368 1389 } else if ($this->getTable()->hasField($key)) { … … 1376 1397 unset($this->$name); 1377 1398 } 1399 } 1400 1401 if ($refresh) { 1402 $this->refresh(); 1378 1403 } 1379 1404 } -
branches/0.11/tests/Record/FromArrayTestCase.php
r4482 r4580 59 59 60 60 # add group 61 $userArray['Group'][ ]['name'] = 'New Group'; # This is a n-m relationship61 $userArray['Group'][0]['name'] = 'New Group'; # This is a n-m relationship 62 62 # add a group which exists 63 $userArray['Group'][1]['id '] = $this->previous_group; # This is a n-m relationship where the group was made in prepareData63 $userArray['Group'][1]['identifier'] = $this->previous_group; # This is a n-m relationship where the group was made in prepareData 64 64 65 65 $user->fromArray($userArray); -
branches/0.11/tests/Record/SynchronizeTestCase.php
r4482 r4580 70 70 $userArray['Group'][]['name'] = 'New Group'; # This is a n-m relationship 71 71 // add a group which exists 72 $userArray['Group'][1]['id '] = $this->previous_group; # This is a n-m relationship where the group was made in prepareData72 $userArray['Group'][1]['identifier'] = $this->previous_group; # This is a n-m relationship where the group was made in prepareData 73 73 74 74 $user->synchronizeWithArray($userArray); -
branches/0.11/tests/run.php
r4566 r4580 292 292 $record->addTestCase(new Doctrine_Record_Inheritance_TestCase()); 293 293 $record->addTestCase(new Doctrine_Record_Synchronize_TestCase()); 294 $record->addTestCase(new Doctrine_Record_Generator_TestCase());295 294 $record->addTestCase(new Doctrine_Record_FromArray_TestCase()); 296 295 $test->addTestCase($record);