From 21efdbf69b031935f812076f106d7aff5c3b7aaf Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 8 Jul 2011 07:13:30 -0700 Subject: [PATCH] Remove insert and update methods from Eloquent. --- system/db/eloquent.php | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/system/db/eloquent.php b/system/db/eloquent.php index fce85ea8..64ab84e3 100644 --- a/system/db/eloquent.php +++ b/system/db/eloquent.php @@ -303,35 +303,22 @@ public function save() $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 @@ public function delete($id = null) return Query::table(static::table(get_class($this)))->delete($this->id); } - return 0; + return $this->query->delete(); } /**