DDC-3603: Readonly columns #4427

Closed
opened 2026-01-22 14:41:23 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 6, 2015).

Jira issue originally created by user sparrowek:

Sometimes I have a column that is calculated (or have a default value) at the database side. When inserting a new record doctrine issues NULL into such a column that causes problems on some DBMS. I would like to annotate such columns as readonly so that doctrine would skip them in INSERT and UPDATE clauses but still fetch them in SELECT clauses.

Originally created by @doctrinebot on GitHub (Mar 6, 2015). Jira issue originally created by user sparrowek: Sometimes I have a column that is calculated (or have a default value) at the database side. When inserting a new record doctrine issues NULL into such a column that causes problems on some DBMS. I would like to annotate such columns as readonly so that doctrine would skip them in INSERT and UPDATE clauses but still fetch them in SELECT clauses.
admin added the New Feature label 2026-01-22 14:41:23 +01:00
admin closed this issue 2026-01-22 14:41:23 +01:00
Author
Owner

@Hikariii commented on GitHub (Mar 21, 2016):

Issued a PR for exactly this: https://github.com/doctrine/doctrine2/pull/5728

@Hikariii commented on GitHub (Mar 21, 2016): Issued a PR for exactly this: https://github.com/doctrine/doctrine2/pull/5728
Author
Owner

@Hikariii commented on GitHub (Jun 15, 2016):

@beberlei This becomes more urgent as more people start using mysql 5.7 and generated columns.
See #5728 for more details on why this is important.

@Hikariii commented on GitHub (Jun 15, 2016): @beberlei This becomes more urgent as more people start using mysql 5.7 and generated columns. See #5728 for more details on why this is important.
Author
Owner

@Ocramius commented on GitHub (Jun 15, 2016):

Described my thoughts about this feature in https://github.com/doctrine/doctrine2/pull/5728

@Ocramius commented on GitHub (Jun 15, 2016): Described my thoughts about this feature in https://github.com/doctrine/doctrine2/pull/5728
Author
Owner

@dbu commented on GitHub (Feb 26, 2019):

as #5728 has been closed, should this be closed too?

if you write your query in dbal, you can completely hide columns from ORM with a schema listener. the column won't be mapped on the entity however, and is not available for DQL / ORM query builder.

@dbu commented on GitHub (Feb 26, 2019): as #5728 has been closed, should this be closed too? if you write your query in dbal, you can [completely hide columns from ORM with a schema listener](https://www.liip.ch/en/blog/doctrine-and-generated-columns). the column won't be mapped on the entity however, and is not available for DQL / ORM query builder.
Author
Owner

@0xPaul commented on GitHub (Dec 20, 2021):

This should not be closed because, as far as I can tell, there still isn't support for read-only generated columns within the ORM.

@0xPaul commented on GitHub (Dec 20, 2021): This should not be closed because, as far as I can tell, there still isn't support for read-only generated columns within the ORM.
Author
Owner

@garak commented on GitHub (Feb 11, 2022):

Readonly on primary keys is not working for me. As soon as I try to hydrate the object, the UnitOfWork tries to call setValue method on the property, resulting in an exception ("Attempting to change readonly property My\Entity\Foo::$id.")

@garak commented on GitHub (Feb 11, 2022): Readonly on primary keys is not working for me. As soon as I try to hydrate the object, the UnitOfWork tries to call `setValue` method on the property, resulting in an exception ("Attempting to change readonly property My\Entity\Foo::$id.")
Author
Owner

@derrabus commented on GitHub (Feb 15, 2022):

@garak The ticket you are commenting on has nothing to with the PHP language feature readonly. Please file a bug for your issue.

@derrabus commented on GitHub (Feb 15, 2022): @garak The ticket you are commenting on has nothing to with the PHP language feature `readonly`. Please file a bug for your issue.
Author
Owner

@beberlei commented on GitHub (Feb 16, 2022):

This was implemented in 2.11 as virtual and generated columns

@beberlei commented on GitHub (Feb 16, 2022): This was implemented in 2.11 as virtual and generated columns
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4427