[PR #9118] Generated/Virtual Columns: Insertable / Updateable #11380

Open
opened 2026-01-22 16:10:36 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/9118

State: closed
Merged: Yes


Defines whether a column is included in an SQL INSERT and/or UPDATE statement.

  • insertable: false - do not include this column as part of INSERT statement for entities of the type.
  • updatable: false - do not include this column as part of UPDATE statement
  • generated: "always" - after inserting or updating this entity, always fetch an updated value from the database.
  • generated: "insert" - after inserting this entity, fetch an updated value from the database.

Use Cases

Map a column several times.

#[Entity] 
class User
{
     #[ManyToOne(targetEntity: Country:class), JoinColumn(name: "country_code", referencedColumnName: "country_code")]
     public $country;
     
     #[Column(type: "string", name: "country_code", insertable: false, updatable: false)]
     public $countryCode;
}

Columns with database updates

#[Entity]
class Article
{
    #[Column(type: "datetime", 
        columnDefinition: "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", 
        insertable: false,
        updatable: false,
        generated: "ALWAYS")]
    public $created;
}

#5728

**Original Pull Request:** https://github.com/doctrine/orm/pull/9118 **State:** closed **Merged:** Yes --- Defines whether a column is included in an SQL INSERT and/or UPDATE statement. * `insertable: false` - do not include this column as part of INSERT statement for entities of the type. * `updatable: false` - do not include this column as part of UPDATE statement * `generated: "always"` - after inserting or updating this entity, always fetch an updated value from the database. * `generated: "insert"` - after inserting this entity, fetch an updated value from the database. ## Use Cases ### Map a column several times. ```php #[Entity] class User { #[ManyToOne(targetEntity: Country:class), JoinColumn(name: "country_code", referencedColumnName: "country_code")] public $country; #[Column(type: "string", name: "country_code", insertable: false, updatable: false)] public $countryCode; } ``` ### Columns with database updates ```php #[Entity] class Article { #[Column(type: "datetime", columnDefinition: "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", insertable: false, updatable: false, generated: "ALWAYS")] public $created; } ``` #5728
admin added the pull-request label 2026-01-22 16:10:36 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#11380