mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
fixed bug when deleting eloquent models.
This commit is contained in:
parent
05b2e28770
commit
285cdcc8f2
@ -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.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user