Commit 285cdcc8 authored by Taylor Otwell's avatar Taylor Otwell

fixed bug when deleting eloquent models.

parent 05b2e287
......@@ -178,12 +178,40 @@ abstract class Eloquent {
*/
public function save()
{
// -----------------------------------------------------
// If the model doesn't have any dirty attributes, there
// is no need to save it to the database.
// -----------------------------------------------------
if ($this->exists and count($this->dirty) == 0)
{
return true;
}
return Eloquent\Warehouse::store($this);
$result = Eloquent\Warehouse::put($this);
// -----------------------------------------------------
// The dirty attributes can be cleared after each save.
// -----------------------------------------------------
$this->dirty = array();
return $result;
}
/**
* Delete a model from the database.
*/
public function delete($id = null)
{
// -----------------------------------------------------
// If the method is being called from an existing model,
// only delete that model from the database.
// -----------------------------------------------------
if ($this->exists)
{
return Eloquent\Warehouse::forget($this);
}
return $this->query->delete($id);
}
/**
......
......@@ -8,7 +8,7 @@ class Warehouse {
* @param object $eloquent
* @return bool
*/
public static function store($eloquent)
public static function put($eloquent)
{
$model = get_class($eloquent);
......@@ -39,6 +39,17 @@ class Warehouse {
return true;
}
/**
* Delete an Eloquent model from the database.
*
* @param object $eloquent
* @return bool
*/
public static function forget($eloquent)
{
return (\System\DB::table(Meta::table(get_class($eloquent)))->where('id', '=', $eloquent->id)->delete() == 1);
}
/**
* Set the activity timestamps on a model.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment