Browse Source

Remove insert and update methods from Eloquent.

Taylor Otwell 13 years ago
parent
commit
21efdbf69b
1 changed files with 11 additions and 24 deletions
  1. 11 24
      system/db/eloquent.php

+ 11 - 24
system/db/eloquent.php

@@ -303,35 +303,22 @@ abstract class Eloquent {
 			$this->timestamp();
 		}
 
-		$result = ($this->exists) ? $this->update() : $this->insert();
+		if ($this->exists)
+		{
+			$result = $this->query->where('id', '=', $this->attributes['id'])->update($this->dirty) == 1;
+		}
+		else
+		{
+			$this->attributes['id'] = $this->query->insert_get_id($this->attributes);
+
+			$result = $this->exists = is_numeric($this->id);
+		}
 
 		$this->dirty = array();
 
 		return $result;
 	}
 
-	/**
-	 * Update an existing model in the database.
-	 *
-	 * @return bool
-	 */
-	private function update()
-	{
-		return $this->query->where('id', '=', $this->attributes['id'])->update($this->dirty) == 1;
-	}
-
-	/**
-	 * Insert a new model into the database.
-	 *
-	 * @return bool
-	 */
-	private function insert()
-	{
-		$this->attributes['id'] = $this->query->insert_get_id($this->attributes);
-
-		return $this->exists = is_numeric($this->id);
-	}
-
 	/**
 	 * Delete a model from the database.
 	 *
@@ -345,7 +332,7 @@ abstract class Eloquent {
 			return Query::table(static::table(get_class($this)))->delete($this->id);
 		}
 
-		return 0;
+		return $this->query->delete();
 	}
 
 	/**