Changeset 851
- Timestamp:
- 10/19/2007 12:19:31 AM (14 months ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
modules/orm/controllers/orm.php (modified) (1 diff)
-
modules/orm/libraries/ORM.php (modified) (2 diffs)
-
system/libraries/drivers/Database_Mysql.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/orm/controllers/orm.php
r848 r851 9 9 $user = new User_Model(1); 10 10 11 $user->first_name = ' Fred';11 $user->first_name = 'Woody'; 12 12 13 print "user: ".Kohana::debug_output($user-> data());13 print "user: ".Kohana::debug_output($user->save()); 14 14 15 15 print Kohana::lang('core.stats_footer'); -
trunk/modules/orm/libraries/ORM.php
r848 r851 139 139 } 140 140 141 // Reset changed variables 142 $this->_changed = array(); 143 141 144 if ( ! empty($this->_relationships['has_one'])) 142 145 { … … 172 175 173 176 /** 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 /** 174 219 * Return object data 175 220 * -
trunk/system/libraries/drivers/Database_Mysql.php
r848 r851 408 408 else // Its an DELETE, INSERT, REPLACE, or UPDATE query 409 409 { 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); 412 412 } 413 413 }
