mirror of
https://github.com/doctrine/orm.git
synced 2026-04-29 09:23:20 +02:00
@Column yields errors when using the 'generated' option. #7401
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @whataboutpereira on GitHub (Jul 28, 2024).
Bug Report
Summary
Using the Column option
generated: 'NEVER'yields an error:Typed property Doctrine\ORM\Mapping\FieldMapping::$generated must not be accessed before initializationCurrent behavior
Using the Column option
generated: 'NEVER'yields an error andgenerated: 'INSERT'works unexpectedly.How to reproduce
Using a database trigger to update a field defined as such:
This yields an error from phpstan (I know I can silence it):
Property App\Entity\User::$unreadComments is never written, only read.This made me look at the 'generated' option and when adding
generated: 'NEVER'to the column options I get the following error:Typed property Doctrine\ORM\Mapping\FieldMapping::$generated must not be accessed before initializationWhen adding
generated: 'INSERT'to the column options, phpstan will be silent, but a SELECT is done after UPDATE to the entity.Expected behavior
generated: 'NEVER'should not yield an error and should not refresh field after update or insert.generated: 'INSERT'should refresh the field after insert, but not after update?Documentation says generated: An enum with the possible values ALWAYS, INSERT, NEVER. Is used after an INSERT or UPDATE statement to determine if the database generated this value and it needs to be fetched using a SELECT statement.
What is the default?
@cjavad commented on GitHub (Sep 29, 2025):
Same issue in 3.5.1
@stof commented on GitHub (Oct 14, 2025):
Please provide a reproducer for this. And also the stack trace. Having an error message without the full info means we are missing lots of useful info to investigate it.
the default is
NEVER, because this is the behavior that makes sense for all fields that are not generated by the database but managed by the ORM. However, when a field value is actually generated by the DB (a rare case among all the usages of theColumnattribute), you most likely want to use a different behavior.@cjavad commented on GitHub (Oct 14, 2025):
For us it appears as a bug in
__sleepiirc, we get it when using Symfony's PhpFileAdapter + cached ClassMetadataFactory, here i trigger the path by invoking orm:validate-schema.With an entity with
#[Column(generated: 'NEVER')]but not INSERT or other options.@cjavad commented on GitHub (Oct 14, 2025):
I created a minimal reproduction using a blank symfony project here http://github.com/cjavad/doctrine-orm-issue-11559 where
bin/console doctrine:schema:validatetriggers the error.@cjavad commented on GitHub (Oct 23, 2025):
@stof is the above enough / repeatable or do you need something more? lmk