Changeset 5034

Show
Ignore:
Timestamp:
10/02/08 07:53:04 (9 months ago)
Author:
jwage
Message:

[1.1] fixes #1281 Added ability to retrieve old values with $record->getModified()

Location:
branches/1.1
Files:
1 added
8 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1/docs/manual/de/component-overview.txt

    r4956 r5034  
    7878$user['age'] = 100; 
    7979 
    80 print_r($user->modifiedFields()); // array('name' => 'Jack Daniels', 'age' => 100); 
     80print_r($user->getModified()); // array('name' => 'Jack Daniels', 'age' => 100); 
    8181 
    8282$user->isModified(); // true 
  • branches/1.1/docs/manual/en/component-overview.txt

    r4956 r5034  
    7878$user['age'] = 100; 
    7979 
    80 print_r($user->modifiedFields()); // array('name' => 'Jack Daniels', 'age' => 100); 
     80print_r($user->getModified()); // array('name' => 'Jack Daniels', 'age' => 100); 
    8181 
    8282$user->isModified(); // true 
  • branches/1.1/docs/manual/ja/component-overview.txt

    r4674 r5034  
    7676$user['age'] = 100; 
    7777 
    78 print_r($user->modifiedFields()); // array('name', 'age'); 
     78print_r($user->getModified()); // array('name', 'age'); 
    7979 
    8080$user->isModified(); // true 
  • branches/1.1/docs/manual/pt_BR/component-overview.txt

    r4956 r5034  
    7878$user['age'] = 100; 
    7979 
    80 print_r($user->modifiedFields()); // array('name' => 'Jack Daniels', 'age' => 100); 
     80print_r($user->getModified()); // array('name' => 'Jack Daniels', 'age' => 100); 
    8181 
    8282$user->isModified(); // true 
  • branches/1.1/lib/Doctrine/Record.php

    r5025 r5034  
    122122 
    123123    /** 
     124     * @var array $_oldValues               an array of the old values from set properties 
     125     */ 
     126    protected $_oldValues   = array(); 
     127 
     128    /** 
    124129     * @var Doctrine_Validator_ErrorStack   error stack object 
    125130     */ 
     
    10721077                $this->_data[$fieldName] = $value; 
    10731078                $this->_modified[] = $fieldName; 
     1079                $this->_oldValues[$fieldName] = $old; 
    10741080 
    10751081                switch ($this->_state) { 
     
    13321338 
    13331339    /** 
    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) 
    13391346    { 
    13401347        $a = array(); 
    13411348 
    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            } 
    13571355        } 
    13581356        return $a; 
  • branches/1.1/tests/run.php

    r5033 r5034  
    122122$tickets->addTestCase(new Doctrine_Ticket_1277_TestCase()); 
    123123$tickets->addTestCase(new Doctrine_Ticket_1280_TestCase()); 
     124$tickets->addTestCase(new Doctrine_Ticket_1281_TestCase()); 
    124125$tickets->addTestCase(new Doctrine_Ticket_1289_TestCase()); 
    125126$tickets->addTestCase(new Doctrine_Ticket_1296_TestCase()); 
  • branches/1.1/tests/Ticket/1134TestCase.php

    r4514 r5034  
    5959        $user = Doctrine_Query::create()->from('Ticket_1134_User u')->fetchOne(); 
    6060                $user->is_pimp = "1"; 
    61                 $this->assertEqual($user->modifiedFields(), FALSE);     
     61                $this->assertEqual($user->getModified(), FALSE);     
    6262    }    
    6363         
  • branches/1.1/UPGRADE_TO_1_1

    r5033 r5034  
    3636    $user->synchronizeWithArray($userArray); 
    3737    $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    */ 
    3858 
    3959Default Options