mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-05 21:28:15 +08:00
Fixed creating,deleting... not work expected.
This commit is contained in:
parent
f8ffaedb1b
commit
fce1695b91
@ -608,8 +608,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->fireModelEvent('deleting') === false) {
|
||||
return false;
|
||||
if ($event = $this->fireModelEvent('deleting')) {
|
||||
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Here, we'll touch the owning models, verifying these timestamps get updated
|
||||
@ -622,7 +624,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
// Once the model has been deleted, we will fire off the deleted event so that
|
||||
// the developers may hook into post-delete operations. We will then return
|
||||
// a boolean true as the delete is presumably successful on the database.
|
||||
$this->fireModelEvent('deleted', false);
|
||||
$this->fireModelEvent('deleted');
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1326,8 +1328,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
// If the updating event returns false, we will cancel the update operation so
|
||||
// developers can hook Validation systems into their models and cancel this
|
||||
// operation if the model does not pass validation. Otherwise, we update.
|
||||
if ($this->fireModelEvent('updating') === false) {
|
||||
return false;
|
||||
if ($event = $this->fireModelEvent('updating')) {
|
||||
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// First we need to create a fresh query instance and touch the creation and
|
||||
@ -1382,8 +1386,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
*/
|
||||
protected function performInsert(Builder $query)
|
||||
{
|
||||
if ($this->fireModelEvent('creating') === false) {
|
||||
return false;
|
||||
if ($event = $this->fireModelEvent('creating')) {
|
||||
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// First we'll need to create a fresh query instance and touch the creation and
|
||||
|
@ -12,6 +12,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Hyperf\Database\Model;
|
||||
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
|
||||
trait SoftDeletes
|
||||
{
|
||||
/**
|
||||
@ -42,7 +44,7 @@ trait SoftDeletes
|
||||
$this->forceDeleting = false;
|
||||
|
||||
if ($deleted) {
|
||||
$this->fireModelEvent('forceDeleted', false);
|
||||
$this->fireModelEvent('forceDeleted');
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -57,8 +59,10 @@ trait SoftDeletes
|
||||
// If the restoring event does not return false, we will proceed with this
|
||||
// restore operation. Otherwise, we bail out so the developer will stop
|
||||
// the restore totally. We will clear the deleted timestamp and save.
|
||||
if ($this->fireModelEvent('restoring') === false) {
|
||||
return false;
|
||||
if ($event = $this->fireModelEvent('restoring')) {
|
||||
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->{$this->getDeletedAtColumn()} = null;
|
||||
@ -70,7 +74,7 @@ trait SoftDeletes
|
||||
|
||||
$result = $this->save();
|
||||
|
||||
$this->fireModelEvent('restored', false);
|
||||
$this->fireModelEvent('restored');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user