Closed Growiel closed 4 years ago
If you use a different name for the Enum and the doctrine type, it is easier to see the difference in where to use them.
Hope this helps you.
Our config/packages/elao_enum.yaml would read something like this:
elao_enum:
doctrine:
types:
App\Enum\EventTypeEnum: eventType
The entity:
/**
* @ORM\Column(type=eventType)
*/
private $type;
If you want to set a default for the type, do it in the constructor:
public function __construct()
{
$this->type = EventTypeEnum::get(EventTypeEnum::TRAINING);
}
Your getters and setters need to use the enum class as well:
public function getType(): ?EventTypeEnum
{
return $this->type;
}
public function setType(?EventTypeEnum $type): self
{
$this->type = $type;
return $this;
}
I'm closing as there is no new feedback here after @pluk77 's answer. Please reopen if we missed something.
Hi there,
I'm using the project as part of a Symfony 5 project, but when I try to save a form using a
ReadableEnum
, I get the following error:The error comes from
Elao\Enum\Bridge\Doctrine\DBAL\Types\AbstractEnumType
in theconvertToDatabaseValue()
method line 57.The method tries to return
$value->getValue()
but, at least in my case,$value
is a simple string containing the value of my enum.I tried with both
as_values
true and false, with similar results.$value
is never an instance ofEnum
.Here's my enum:
Here's the form that implements it:
The relevant part of the
config/packages/elao_enum.yaml
file:And finally, the entity where the enum is mapped:
What am I missing ?
Thanks !