Changeset 4772

Show
Ignore:
Timestamp:
08/15/08 10:54:16 (11 months ago)
Author:
romanb
Message:

Fixed #1277. Added coverage for #1254.

Location:
branches/1.0
Files:
2 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/lib/Doctrine/Record.php

    r4770 r4772  
    515515    { 
    516516        $this->_values = array_merge($this->_values, $this->cleanData($data)); 
    517         $this->_data   = array_merge($this->_data, $data); 
     517        $this->_data = array_merge($this->_data, $data); 
    518518        $this->prepareIdentifiers(true); 
    519519    } 
     
    829829    /** 
    830830     * load 
    831      * loads all the uninitialized properties from the database 
     831     * Loads all the uninitialized properties from the database. 
     832     * Used to move a record from PROXY to CLEAN/DIRTY state. 
    832833     * 
    833834     * @return boolean 
    834835     */ 
    835     public function load() 
     836    public function load(array $data = array()) 
    836837    { 
    837838        // only load the data from database if the Doctrine_Record is in proxy state 
    838839        if ($this->_state == Doctrine_Record::STATE_PROXY) { 
    839             $this->refresh(); 
    840             $this->_state = Doctrine_Record::STATE_CLEAN; 
     840            $id = $this->identifier(); 
     841            if ( ! is_array($id)) { 
     842                $id = array($id); 
     843            } 
     844            if (empty($id)) { 
     845                return false; 
     846            } 
     847 
     848            $data = empty($data) ? $this->getTable()->find($id, Doctrine::HYDRATE_ARRAY) : $data; 
     849            foreach ($data as $field => $value) { 
     850               if ( ! isset($this->_data[$field]) || $this->_data[$field] === self::$_null) { 
     851                   $this->_data[$field] = $value; 
     852               } 
     853            } 
     854             
     855            if ($this->isModified()) { 
     856               $this->_state = Doctrine_Record::STATE_DIRTY; 
     857            } else if (count($data) >= $this->_table->getColumnCount()) { 
     858                $this->_state = Doctrine_Record::STATE_CLEAN; 
     859            } 
     860            $this->cleanData($this->_data); 
    841861            return true; 
    842862        } 
     
    941961            if ($this->_isValueModified($type, $old, $value)) { 
    942962                if ($value === null) { 
    943                     $default = $this->_table->getDefaultValueOf($fieldName); 
     963                    $default = $this->_table->getDefaultValueOf($fieldName);  
    944964                    $value = ($default === null) ? self::$_null : $default; 
    945965                } 
    946  
    947966                $this->_data[$fieldName] = $value; 
    948967                $this->_modified[] = $fieldName; 
     968 
    949969                switch ($this->_state) { 
    950970                    case Doctrine_Record::STATE_CLEAN: 
     971                    case Doctrine_Record::STATE_PROXY: 
    951972                        $this->_state = Doctrine_Record::STATE_DIRTY; 
    952973                        break; 
     
    12551276            } 
    12561277        } 
    1257  
    12581278        $map = $this->_table->inheritanceMap; 
    12591279        foreach ($map as $k => $v) { 
     
    18481868            foreach ($ids as $id) { 
    18491869                $record = new $modelClassName; 
    1850                 $record[$localFieldName]   = $identifier; 
     1870                $record[$localFieldName] = $identifier; 
    18511871                $record[$foreignFieldName] = $id; 
    18521872                $record->save(); 
  • branches/1.0/lib/Doctrine/Table.php

    r4768 r4772  
    14311431                return $record; 
    14321432            } 
    1433  
    1434  
     1433             
    14351434            $id = implode(' ', $id); 
    14361435 
    14371436            if (isset($this->_identityMap[$id])) { 
     1437                //NOTE: This is still flawed as modifications are overridden in hydrate() 
    14381438                $record = $this->_identityMap[$id]; 
    14391439                $record->hydrate($this->_data); 
     1440                if ($record->state() == Doctrine_Record::STATE_PROXY) { 
     1441                    if (count($this->_data) >= $this->getColumnCount()) { 
     1442                        $record->state(Doctrine_Record::STATE_CLEAN); 
     1443                    } 
     1444                } 
    14401445            } else { 
    14411446                $recordName = $this->getComponentName(); 
  • branches/1.0/tests/run.php

    r4770 r4772  
    102102$tickets->addTestCase(new Doctrine_Ticket_1251_TestCase()); 
    103103$tickets->addTestCase(new Doctrine_Ticket_1253_TestCase()); 
     104$tickets->addTestCase(new Doctrine_Ticket_1254_TestCase()); 
    104105$tickets->addTestCase(new Doctrine_Ticket_1257_TestCase()); 
     106$tickets->addTestCase(new Doctrine_Ticket_1277_TestCase()); 
    105107$tickets->addTestCase(new Doctrine_Ticket_1289_TestCase()); 
    106108$tickets->addTestCase(new Doctrine_Ticket_1296_TestCase());