Final Class Yiisoft\ActiveRecord\Event\Handler\SoftDelete
| Inheritance | Yiisoft\ActiveRecord\Event\Handler\SoftDelete » Yiisoft\ActiveRecord\Event\Handler\AttributeHandlerProvider |
|---|
Attribute for implementing soft deletion in Active Record models. Instead of deleting records from the database, it sets a value of the date and time for properties to indicate that the record has been logically deleted.
By default, it sets the current date and time to the deleted_at property.
It can be applied to classes or properties, and it can be repeated for multiple properties.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ActiveRecord\Event\Handler\SoftDelete | |
| getEventHandlers() | Yiisoft\ActiveRecord\Event\Handler\SoftDelete | |
| getPropertyNames() | Returns the list of property names the handler should be applied to. | Yiisoft\ActiveRecord\Event\Handler\AttributeHandlerProvider |
| setPropertyNames() | Sets the list of property names the handler should be applied to. | Yiisoft\ActiveRecord\Event\Handler\AttributeHandlerProvider |
Method Details
| public mixed __construct ( mixed $value = null, string $propertyNames ) | ||
| $value | mixed | |
| $propertyNames | string | |
public function __construct(
private mixed $value = null,
string ...$propertyNames,
) {
$this->value ??= static fn(): DateTimeImmutable => new DateTimeImmutable();
if (empty($propertyNames)) {
$propertyNames = ['deleted_at'];
}
parent::__construct(...$propertyNames);
}
| public array getEventHandlers ( ) |
public function getEventHandlers(): array
{
return [
AfterCreateQuery::class => $this->afterCreateQuery(...),
BeforeDelete::class => $this->beforeDelete(...),
];
}
Defined in: Yiisoft\ActiveRecord\Event\Handler\AttributeHandlerProvider::getPropertyNames()
Returns the list of property names the handler should be applied to.
| public string[] getPropertyNames ( ) |
public function getPropertyNames(): array
{
return $this->propertyNames;
}
Defined in: Yiisoft\ActiveRecord\Event\Handler\AttributeHandlerProvider::setPropertyNames()
Sets the list of property names the handler should be applied to.
| public void setPropertyNames ( string[] $propertyNames ) | ||
| $propertyNames | string[] | |
public function setPropertyNames(array $propertyNames): void
{
$this->propertyNames = $propertyNames;
}
Signup or Login in order to comment.