Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realize ReadOnlyActiveRecord #313

Open
Tigrov opened this issue May 15, 2024 · 4 comments
Open

Realize ReadOnlyActiveRecord #313

Tigrov opened this issue May 15, 2024 · 4 comments

Comments

@Tigrov
Copy link
Member

Tigrov commented May 15, 2024

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

@samdark
Copy link
Member

samdark commented May 15, 2024

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
    )
    {}

    // ...
}

@Tigrov
Copy link
Member Author

Tigrov commented May 16, 2024

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()

@vjik
Copy link
Member

vjik commented May 18, 2024

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.

@Tigrov
Copy link
Member Author

Tigrov commented May 21, 2024

Seems readonly class is not suitable due to relations stored in $relation property. And the relations can be loaded in several operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants