Changeset 263 for trunk/trax/vendor/trax

Show
Ignore:
Timestamp:
09/03/06 22:50:57 (6 years ago)
Author:
john
Message:

updates to composed_of

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/active_record.php

    r262 r263  
    433433 
    434434        # If $attributes array is passed in update the class with its contents 
    435         if(is_array($attributes)) { 
    436             $this->update_attributes($attributes); 
    437         } 
     435        $this->update_attributes($attributes); 
    438436    } 
    439437 
     
    15541552        //error_log("ActiveRecord::save() \$attributes=" 
    15551553        //          . var_export($attributes,true)); 
    1556         if(is_array($attributes)) { 
    1557             $this->update_attributes($attributes); 
    1558         } 
    1559         if ($dont_validate || $this->valid()) { 
     1554        $this->update_attributes($attributes); 
     1555        if($dont_validate || $this->valid()) { 
    15601556            return $this->add_record_or_update_record(); 
    15611557        } else { 
     
    16291625            $this->raise($primary_key_value->getMessage()); 
    16301626        } 
     1627        $this->update_composite_attributes(); 
    16311628        $attributes = $this->get_inserts(); 
    16321629        $fields = @implode(', ', array_keys($attributes)); 
     
    16341631        $sql = "INSERT INTO {$this->table_name} ($fields) VALUES ($values)"; 
    16351632        //echo "add_record: SQL: $sql<br>"; 
    1636         error_log("add_record: SQL: $sql"); 
     1633        //error_log("add_record: SQL: $sql"); 
    16371634        $result = $this->query($sql); 
    16381635         
     
    16811678    private function update_record() { 
    16821679        //error_log('update_record()'); 
     1680        $this->update_composite_attributes(); 
    16831681        $updates = $this->get_updates_sql(); 
    16841682        $conditions = $this->get_primary_key_conditions(); 
    16851683        $sql = "UPDATE {$this->table_name} SET {$updates} WHERE {$conditions}"; 
    16861684        //echo "update_record:$sql<br>"; 
    1687         error_log("update_record: SQL: $sql"); 
     1685        //error_log("update_record: SQL: $sql"); 
    16881686        $result = $this->query($sql); 
    16891687        if($this->is_error($result)) { 
     
    17091707    private function get_composite_object($name) { 
    17101708        $composite_object = null; 
     1709        $composite_attributes = array(); 
    17111710        if(is_array($this->composed_of)) {  
    17121711            if(array_key_exists($name, $this->composed_of)) { 
    17131712                $class_name = Inflector::classify(($this->composed_of[$name]['class_name'] ?  
    17141713                    $this->composed_of[$name]['class_name'] : $name));            
    1715                 if(class_exists($class_name)) { 
    1716                     $composite_object = new $class_name(); 
    1717                     $mappings = $this->composed_of[$name]['mapping']; 
    1718                     if(is_array($mappings)) { 
    1719                         foreach($mappings as $database_name => $composite_name) { 
    1720                             $composite_object->$composite_name = $this->$database_name;                           
    1721                         }     
    1722                     }       
    1723                 } 
     1714 
     1715                $mappings = $this->composed_of[$name]['mapping']; 
     1716                if(is_array($mappings)) { 
     1717                    foreach($mappings as $database_name => $composite_name) { 
     1718                        $composite_attributes[$composite_name] = $this->$database_name;                       
     1719                    }     
     1720                }    
    17241721            }     
    17251722        } elseif($this->composed_of == $name) { 
    1726             $class_name = Inflector::classify($name); 
    1727             if(class_exists($class_name)) { 
    1728                 $composite_object = new $class_name(); 
    1729                 $composite_object->$name = $this->$name;             
    1730             } 
     1723            $class_name = $name; 
     1724            $composite_attributes[$name] = $this->$name;         
    17311725        }  
    17321726         
    1733         if(is_object($composite_object)) { 
    1734             if(method_exists($composite_object, 'initialize')) { 
    1735                 $composite_object->initialize(); 
    1736             }             
    1737         } 
    1738          
     1727        if(class_exists($class_name)) {                      
     1728            $composite_object = new $class_name;         
     1729            if($composite_object->auto_map_attributes !== false) { 
     1730                //echo "auto_map_attributes<br>"; 
     1731                foreach($composite_attributes as $name => $value) { 
     1732                    $composite_object->$name = $value;     
     1733                }                                       
     1734            }            
     1735            if(method_exists($composite_object, '__construct')) { 
     1736                //echo "calling constructor<br>"; 
     1737                $composite_object->__construct($composite_attributes);        
     1738            }          
     1739        }  
    17391740        return $composite_object; 
    17401741    } 
     
    21562157            } 
    21572158            $this->set_habtm_attributes($attributes); 
    2158             $this->update_composite_attributes(); 
    21592159        } 
    21602160    }