Suggestion: Add comment to @JoinColumn (i.e. to foreign key) #6552

Open
opened 2026-01-22 15:34:55 +01:00 by admin · 3 comments
Owner

Originally created by @ThomasLandauer on GitHub (Oct 12, 2020).

Since the foreign key field is generated automatically by Doctrine, there's no way to add a column comment to it. So I'm suggesting to enable the same system from @Column

@ORM\Column(options={"comment":"My comment"})

for @JoinColumn too:

@ORM\JoinColumn(options={"comment":"My comment"})

This has been suggested before, see https://github.com/doctrine/orm/issues/4075#issuecomment-162366414

Originally created by @ThomasLandauer on GitHub (Oct 12, 2020). Since the foreign key field is generated automatically by Doctrine, there's no way to add a column comment to it. So I'm suggesting to enable the same system from [@Column](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/annotations-reference.html#column) ```php @ORM\Column(options={"comment":"My comment"}) ``` for [@JoinColumn](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/annotations-reference.html#joincolumn) too: ```php @ORM\JoinColumn(options={"comment":"My comment"}) ``` This has been suggested before, see https://github.com/doctrine/orm/issues/4075#issuecomment-162366414
Author
Owner

@codemistake commented on GitHub (May 16, 2022):

Nobody found a solution? Looks like basic functionality

@codemistake commented on GitHub (May 16, 2022): Nobody found a solution? Looks like basic functionality
Author
Owner

@greg0ire commented on GitHub (May 17, 2022):

@codemistake consider contributing it.

@greg0ire commented on GitHub (May 17, 2022): @codemistake consider contributing it.
Author
Owner

@xcy7e commented on GitHub (Jun 17, 2022):

You could work around this using columnDefinition attribute.

    /**
     * @ORM\JoinColumn(columnDefinition="INT NOT NULL COMMENT 'Here is my explanation'")
     */
    private $field;

Keep in mind you will have to put the whole column specs when using columnDefinition!

reference: joinColumn Attributes

@xcy7e commented on GitHub (Jun 17, 2022): You could work around this using `columnDefinition` attribute. ```php /** * @ORM\JoinColumn(columnDefinition="INT NOT NULL COMMENT 'Here is my explanation'") */ private $field; ``` **Keep in mind you will have to put the whole column specs when using `columnDefinition`!** [reference: joinColumn Attributes](https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/reference/attributes-reference.html#joincolumn-inversejoincolumn)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6552