Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      It should be possible to mark an entity class as read-only so that it is never considered for change-tracking after it has been initially inserted into the database.

      This feature is mainly a flush performance tweak to avoid checking objects for changes which can never actually change.

        Activity

        Hide
        Christian Heinrich added a comment -

        Roman, could you point out how exactly you expect this to work?

        I mean, when you create a new entity and persist it, you surely need to track updates to the entity-to-be-persisted.

        Additionally, what about entities that are expected to be updated only in one place, like a service. Should there be a possibility to enforce updating?

        Show
        Christian Heinrich added a comment - Roman, could you point out how exactly you expect this to work? I mean, when you create a new entity and persist it, you surely need to track updates to the entity-to-be-persisted. Additionally, what about entities that are expected to be updated only in one place, like a service. Should there be a possibility to enforce updating?
        Hide
        Marc Hodgins added a comment - - edited

        For us, I see a use case for summary tables (i.e. Post and PostViews – a roll up of log data into computed "most popular", "most commented", views per day/week/month, etc). The data is generated outside of Doctrine (i.e. directly via DBAL, or stored procedures) but we still want to define the relationships of other entities to this data so we can access it on a read-only basis in DQL and the object graph. We would flag these as read-only as there is no need for change-tracking. Example:

        /** @Entity */
        class Post {
            /** @OneToMany(targetEntity="PostViews" ...) */
            protected $views;
        }
        /** @Entity @ReadOnly */
        class PostViews { /* summary table computed via stored procedure */
        
           public function __construct() { throw new \Exception('Entity is read only'); }
        
            /** @Column */
            protected $period; // day, week, month, year, etc.
        
           /** @Column */
           protected $viewCount;
        }
        

        Regarding Roman's description of persist-only and then no updates, isn't this more like @PersistOnly rather than @ReadOnly? Or you could generalize this further with a tag like @AllowedActions={"persist", "update", "delete"} ?

        /** @Entity @PersistOnly */
        class A {
            /** @Column */
           protected $foo;
           
          public function __construct($foo) {
             $this->foo = $foo;
          }
        
          public function getFoo() {
            return $this->foo;
          }
        }
        

        Is this what you have in mind Roman?

        Show
        Marc Hodgins added a comment - - edited For us, I see a use case for summary tables (i.e. Post and PostViews – a roll up of log data into computed "most popular", "most commented", views per day/week/month, etc). The data is generated outside of Doctrine (i.e. directly via DBAL, or stored procedures) but we still want to define the relationships of other entities to this data so we can access it on a read-only basis in DQL and the object graph. We would flag these as read-only as there is no need for change-tracking. Example: /** @Entity */ class Post { /** @OneToMany(targetEntity= "PostViews" ...) */ protected $views; } /** @Entity @ReadOnly */ class PostViews { /* summary table computed via stored procedure */ public function __construct() { throw new \Exception('Entity is read only'); } /** @Column */ protected $period; // day, week, month, year, etc. /** @Column */ protected $viewCount; } Regarding Roman's description of persist-only and then no updates, isn't this more like @PersistOnly rather than @ReadOnly? Or you could generalize this further with a tag like @AllowedActions={"persist", "update", "delete"} ? /** @Entity @PersistOnly */ class A { /** @Column */ protected $foo; public function __construct($foo) { $ this ->foo = $foo; } public function getFoo() { return $ this ->foo; } } Is this what you have in mind Roman?
        Hide
        Benjamin Eberlei added a comment -

        Implemented.

        Show
        Benjamin Eberlei added a comment - Implemented.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Roman S. Borschel
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: