Skip to content

Realize ReadOnlyActiveRecord #313

Open

Description

@Tigrov

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

Activity

  1. samdark commented on May 15, 2024

    @samdark
    Member

    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
        )
        {}
    
        // ...
    }
  2. Tigrov commented on May 16, 2024

    @Tigrov
    MemberAuthor

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

  3. vjik commented on May 18, 2024

    @vjik
    Member

    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.

  4. Tigrov commented on May 21, 2024

    @Tigrov
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions