Skip to content

DDC-692: Read-only entities #5203

Closed
doctrinebot opened this Issue Jul 15, 2010 · 4 comments

2 participants

@doctrinebot

Jira issue originally created by user romanb:

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.

@doctrinebot

Comment created by shurakai:

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?

@doctrinebot

Comment created by mjh_ca:

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?

@doctrinebot

Comment created by @beberlei:

Implemented.

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.