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;
/** @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?
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?