Changeset 5034
- Timestamp:
- 10/02/08 07:53:04 (9 months ago)
- Location:
- branches/1.1
- Files:
-
- 1 added
- 8 modified
-
docs/manual/de/component-overview.txt (modified) (1 diff)
-
docs/manual/en/component-overview.txt (modified) (1 diff)
-
docs/manual/ja/component-overview.txt (modified) (1 diff)
-
docs/manual/pt_BR/component-overview.txt (modified) (1 diff)
-
lib/Doctrine/Record.php (modified) (3 diffs)
-
tests/run.php (modified) (1 diff)
-
tests/Ticket/1134TestCase.php (modified) (1 diff)
-
tests/Ticket/1281TestCase.php (added)
-
UPGRADE_TO_1_1 (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1/docs/manual/de/component-overview.txt
r4956 r5034 78 78 $user['age'] = 100; 79 79 80 print_r($user-> modifiedFields()); // array('name' => 'Jack Daniels', 'age' => 100);80 print_r($user->getModified()); // array('name' => 'Jack Daniels', 'age' => 100); 81 81 82 82 $user->isModified(); // true -
branches/1.1/docs/manual/en/component-overview.txt
r4956 r5034 78 78 $user['age'] = 100; 79 79 80 print_r($user-> modifiedFields()); // array('name' => 'Jack Daniels', 'age' => 100);80 print_r($user->getModified()); // array('name' => 'Jack Daniels', 'age' => 100); 81 81 82 82 $user->isModified(); // true -
branches/1.1/docs/manual/ja/component-overview.txt
r4674 r5034 76 76 $user['age'] = 100; 77 77 78 print_r($user-> modifiedFields()); // array('name', 'age');78 print_r($user->getModified()); // array('name', 'age'); 79 79 80 80 $user->isModified(); // true -
branches/1.1/docs/manual/pt_BR/component-overview.txt
r4956 r5034 78 78 $user['age'] = 100; 79 79 80 print_r($user-> modifiedFields()); // array('name' => 'Jack Daniels', 'age' => 100);80 print_r($user->getModified()); // array('name' => 'Jack Daniels', 'age' => 100); 81 81 82 82 $user->isModified(); // true -
branches/1.1/lib/Doctrine/Record.php
r5025 r5034 122 122 123 123 /** 124 * @var array $_oldValues an array of the old values from set properties 125 */ 126 protected $_oldValues = array(); 127 128 /** 124 129 * @var Doctrine_Validator_ErrorStack error stack object 125 130 */ … … 1072 1077 $this->_data[$fieldName] = $value; 1073 1078 $this->_modified[] = $fieldName; 1079 $this->_oldValues[$fieldName] = $old; 1074 1080 1075 1081 switch ($this->_state) { … … 1332 1338 1333 1339 /** 1334 * returns an array of modified fields and associated values 1335 * @return array 1336 * @todo What about a better name? getModifiedFields? 1337 */ 1338 public function getModified() 1340 * returns an array of modified fields and associated new values 1341 * specify $old = true to retrieve an array with the old values 1342 * 1343 * @return array $a 1344 */ 1345 public function getModified($old = false) 1339 1346 { 1340 1347 $a = array(); 1341 1348 1342 foreach ($this->_modified as $k => $v) { 1343 $a[$v] = $this->_data[$v]; 1344 } 1345 return $a; 1346 } 1347 1348 /** 1349 * REDUNDANT? 1350 */ 1351 public function modifiedFields() 1352 { 1353 $a = array(); 1354 1355 foreach ($this->_modified as $k => $v) { 1356 $a[$v] = $this->_data[$v]; 1349 foreach ($this->_modified as $fieldName) { 1350 if ($old) { 1351 $a[$fieldName] = $this->_oldValues[$fieldName]; 1352 } else { 1353 $a[$fieldName] = $this->_data[$fieldName]; 1354 } 1357 1355 } 1358 1356 return $a; -
branches/1.1/tests/run.php
r5033 r5034 122 122 $tickets->addTestCase(new Doctrine_Ticket_1277_TestCase()); 123 123 $tickets->addTestCase(new Doctrine_Ticket_1280_TestCase()); 124 $tickets->addTestCase(new Doctrine_Ticket_1281_TestCase()); 124 125 $tickets->addTestCase(new Doctrine_Ticket_1289_TestCase()); 125 126 $tickets->addTestCase(new Doctrine_Ticket_1296_TestCase()); -
branches/1.1/tests/Ticket/1134TestCase.php
r4514 r5034 59 59 $user = Doctrine_Query::create()->from('Ticket_1134_User u')->fetchOne(); 60 60 $user->is_pimp = "1"; 61 $this->assertEqual($user-> modifiedFields(), FALSE);61 $this->assertEqual($user->getModified(), FALSE); 62 62 } 63 63 -
branches/1.1/UPGRADE_TO_1_1
r5033 r5034 36 36 $user->synchronizeWithArray($userArray); 37 37 $user->save(); 38 39 [r5034](http://trac.doctrine-project.org/changeset/5034) - You can now retrieve the old values of records through the getModified() function. By default it returns an array of fieldName => newValue but if you specify getModified(true) it will return the old values. 40 41 $users = Doctrine::getTable('User')->findAll(); 42 $user = $users->getFirst(); 43 $user->name = 'zYne-'; 44 45 $oldValues = $user->getModified(true); 46 /* 47 array( 48 'name' => 'zYne', 49 ) 50 */ 51 52 $newValues = $user->getModified(false); 53 /* 54 array( 55 'name' => 'zYne-', 56 ) 57 */ 38 58 39 59 Default Options