Skip to content

@Column yields errors when using the 'generated' option. #11559

@whataboutpereira

Description

@whataboutpereira

Bug Report

Q A
BC Break no
Version 3.2.1

Summary

Using the Column option generated: 'NEVER' yields an error:

Typed property Doctrine\ORM\Mapping\FieldMapping::$generated must not be accessed before initialization

Current behavior

Using the Column option generated: 'NEVER' yields an error and generated: 'INSERT' works unexpectedly.

How to reproduce

Using a database trigger to update a field defined as such:

    #[ORM\Column(
        name: 'UnreadComments',
        options: ['unsigned' => true, 'default' => 0],
        insertable: false,
        updatable: false,
    )]

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 initialization

When 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions