Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Doctrine] Add documentation for Enum usage #19169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 6.4
Choose a base branch
Loading
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
review
  • Loading branch information
MrYamous authored Nov 22, 2023
commit 54604137bbcba3e296507ea83054cc0f40c71a13
16 changes: 8 additions & 8 deletions 16 doctrine/use_enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ First step is to create an enum::
// src/Enum/Suit.php
namespace App\Enum;

enum Suit: string {
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
enum Suit: string {
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
}

.. note::
Expand All @@ -26,13 +26,13 @@ When the enum is created, you can use the ``enumType`` parameter of
``#[ORM\Column]`` attribute or use it directly for a more typed property::

// src/Entity/Card.php
namespace App\Enum;
namespace App\Entity;

#[Column(type: Types::TEXT, enumType: Suit::class)]
#[Column(type: Types::STRING, enumType: Suit::class)]
public string $suit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a rare use case to map a property using a BackedEnum and not use it in the model; I wouldn't show this case. I think the above example should be the only one documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. I'm quite in favour of showing both even if one use is rare and let developers choose the one that fit to their needs. Maybe we can add a comment to point which is the most common/recommended way ?


// or for a more typed property
#[Column(type: Types::TEXT)]
#[Column(type: Types::STRING)]
public Suit $suit;

.. caution::
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.