active-record
active-record copied to clipboard
Realize `ReadOnlyActiveRecord`
There are cases when ActiveRecord instances should be used in readonly mode. For example, readonly tables or views (virtual tables) and views for rendering responses.
For these cases ReadOnlyActiveRecordInterface interface could be created and realized in ReadOnlyActiveRecord class.
Updated 16.05.2024
Found related issue with naming ImmutableActiveRecord
- https://github.com/yiisoft/yii2/issues/10459
Can we use native PHP readonly properties (PHP 8.1) and classes (PHP 8.2) for the purpose?
readonly class User
{
// ...
}
class User
{
public function __construct(
public readonly string $name
)
{}
// ...
}
Can we use native PHP readonly properties (PHP 8.1) and classes (PHP 8.2) for the purpose?
Looks like a solution but still can be deleted using $model->delete()
May be add this feature in PHP 8.2 only? It will to allow check readonly class in delete() method and throw exception in this case.
Seems readonly class is not suitable due to relations stored in $relation property. And the relations can be loaded in several operations.