Changeset 851

Show
Ignore:
Timestamp:
10/19/2007 12:19:31 AM (14 months ago)
Author:
Shadowhand
Message:

Small changes:

  • Fixed a reference to num_rows in Mysql_Result
  • Added ORM::save()
Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/orm/controllers/orm.php

    r848 r851  
    99                $user = new User_Model(1); 
    1010 
    11                 $user->first_name = 'Fred'; 
     11                $user->first_name = 'Woody'; 
    1212 
    13                 print "user: ".Kohana::debug_output($user->data()); 
     13                print "user: ".Kohana::debug_output($user->save()); 
    1414 
    1515                print Kohana::lang('core.stats_footer'); 
  • trunk/modules/orm/libraries/ORM.php

    r848 r851  
    139139                        } 
    140140 
     141                        // Reset changed variables 
     142                        $this->_changed = array(); 
     143 
    141144                        if ( ! empty($this->_relationships['has_one'])) 
    142145                        { 
     
    172175 
    173176        /** 
     177         * Save an object 
     178         * 
     179         * @access public 
     180         * @return boolean 
     181         */ 
     182        public function save() 
     183        { 
     184                if (empty($this->_where)) 
     185                { 
     186                        // Do an insert 
     187                        if ($id = self::$db->insert($this->_table, $this->data())->insert_id()) 
     188                        { 
     189                                $this->id = $id; 
     190                                $this->_where = array('id' => $id); 
     191 
     192                                return TRUE; 
     193                        } 
     194                } 
     195                elseif (empty($this->_changed)) 
     196                { 
     197                        // No data has changed 
     198                        return TRUE; 
     199                } 
     200                else 
     201                { 
     202                        // Fetch data 
     203                        $data = $this->data(); 
     204 
     205                        // Remove id, to prevent updates 
     206                        unset($data['id']); 
     207 
     208                        // Do an update 
     209                        if (count(self::$db->update($this->_table, $data, $this->_where)) > 0) 
     210                        { 
     211                                return TRUE; 
     212                        } 
     213                } 
     214 
     215                return FALSE; 
     216        } 
     217 
     218        /** 
    174219         * Return object data 
    175220         * 
  • trunk/system/libraries/drivers/Database_Mysql.php

    r848 r851  
    408408                        else // Its an DELETE, INSERT, REPLACE, or UPDATE query 
    409409                        { 
    410                                 $this->insert_id = mysql_insert_id($link); 
    411                                 $this->num_rows = mysql_affected_rows($link); 
     410                                $this->insert_id  = mysql_insert_id($link); 
     411                                $this->total_rows = mysql_affected_rows($link); 
    412412                        } 
    413413                }