Changeset 2183
- Timestamp:
- 02/28/2008 10:50:07 AM (9 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/ORM.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/ORM.php
r2180 r2183 28 28 protected $class; 29 29 protected $table; 30 31 // Primary column name 32 protected $primary_column = 'id'; 30 33 31 34 // SQL building status … … 134 137 // Set the model name 135 138 $model = ucfirst($key).'_Model'; 136 137 if (empty($this->object->id)) 139 140 $idcolumn = $this->primary_column; 141 142 if (empty($this->object->$idcolumn)) 138 143 { 139 144 // Load an empty model … … 149 154 ? $this->object->$child_id 150 155 // Get the foreign object using the primary key of this object 151 : array($this->class.'_id', $this->object-> id));156 : array($this->class.'_id', $this->object->$idcolumn)); 152 157 } 153 158 … … 171 176 } 172 177 } 178 173 179 174 180 /** … … 470 476 protected function where_key($id = NULL) 471 477 { 472 return $this->table.'. id';478 return $this->table.'.'.$this->primary_column; 473 479 } 474 480 … … 518 524 if (empty($this->changed)) 519 525 return TRUE; 526 527 $idcolumn = $this->primary_column; 520 528 521 529 $data = array(); … … 526 534 } 527 535 528 if ($this->object-> id== '')536 if ($this->object->$idcolumn == '') 529 537 { 530 538 // Perform an insert … … 534 542 { 535 543 // Set current object id by the insert id 536 $this->object-> id= $query->insert_id();544 $this->object->$idcolumn = $query->insert_id(); 537 545 } 538 546 } … … 540 548 { 541 549 // Perform an update 542 $query = self::$db->update($this->table, $data, array( 'id' => $this->object->id));550 $query = self::$db->update($this->table, $data, array($idcolumn => $this->object->$idcolumn)); 543 551 } 544 552 … … 790 798 self::$db->where("$join.$primary", $this->object->id)->join($join, "$join.$foreign", "$table.id"); 791 799 } 792 793 800 } // End ORM 794 801
