Closed
Description
BC Break Report
Q | A |
---|---|
BC Break | yes |
Version | 2.13.2 |
Summary
After upgraded to the latest version, we are having trouble hydrating entities containing an enum, after a DQL query
Current behavior
App\Entity\Enum\ArticleState::from(): Argument #1 ($value) must be of type string, App\Entity\Enum\ArticleState given
How to reproduce
- Create the entity
class Article
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, enumType: ArticleState::class)]
private ?ArticleState $state = null;
public function getId(): ?int
{
return $this->id;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getState(): ?ArticleState
{
return $this->state;
}
public function setState(ArticleState $state): self
{
$this->state = $state;
return $this;
}
}
- Create the enum
enum ArticleState: string
{
case ONLINE = 'online';
case OFFLINE = 'offline';
}
- Add the repository request
/**
* @return Article[]
*/
public function findByState(ArticleState $articleState): array
{
return $this->createQueryBuilder('a')
->andWhere('a.state = :state')
->setParameter('state', $articleState->value)
->getQuery()
->getResult();
}
- Try the request, and you will get this error :
App\Entity\Enum\ArticleState::from(): Argument #1 ($value) must be of type string, App\Entity\Enum\ArticleState given
Reproducer
https://github.com/bastien70/enum-reproducer
EDIT : duplicate of #10058
Metadata
Metadata
Assignees
Labels
No labels