Changeset 263 for trunk/trax/vendor/trax
- Timestamp:
- 09/03/06 22:50:57 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/active_record.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/active_record.php
r262 r263 433 433 434 434 # 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); 438 436 } 439 437 … … 1554 1552 //error_log("ActiveRecord::save() \$attributes=" 1555 1553 // . 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()) { 1560 1556 return $this->add_record_or_update_record(); 1561 1557 } else { … … 1629 1625 $this->raise($primary_key_value->getMessage()); 1630 1626 } 1627 $this->update_composite_attributes(); 1631 1628 $attributes = $this->get_inserts(); 1632 1629 $fields = @implode(', ', array_keys($attributes)); … … 1634 1631 $sql = "INSERT INTO {$this->table_name} ($fields) VALUES ($values)"; 1635 1632 //echo "add_record: SQL: $sql<br>"; 1636 error_log("add_record: SQL: $sql");1633 //error_log("add_record: SQL: $sql"); 1637 1634 $result = $this->query($sql); 1638 1635 … … 1681 1678 private function update_record() { 1682 1679 //error_log('update_record()'); 1680 $this->update_composite_attributes(); 1683 1681 $updates = $this->get_updates_sql(); 1684 1682 $conditions = $this->get_primary_key_conditions(); 1685 1683 $sql = "UPDATE {$this->table_name} SET {$updates} WHERE {$conditions}"; 1686 1684 //echo "update_record:$sql<br>"; 1687 error_log("update_record: SQL: $sql");1685 //error_log("update_record: SQL: $sql"); 1688 1686 $result = $this->query($sql); 1689 1687 if($this->is_error($result)) { … … 1709 1707 private function get_composite_object($name) { 1710 1708 $composite_object = null; 1709 $composite_attributes = array(); 1711 1710 if(is_array($this->composed_of)) { 1712 1711 if(array_key_exists($name, $this->composed_of)) { 1713 1712 $class_name = Inflector::classify(($this->composed_of[$name]['class_name'] ? 1714 1713 $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 } 1724 1721 } 1725 1722 } 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; 1731 1725 } 1732 1726 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 } 1739 1740 return $composite_object; 1740 1741 } … … 2156 2157 } 2157 2158 $this->set_habtm_attributes($attributes); 2158 $this->update_composite_attributes();2159 2159 } 2160 2160 }
