8000 Enum - XXX::from(): Argument #1 ($value) must be of type string, XXX given · Issue #10069 · doctrine/orm · GitHub 8000
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Enum - XXX::from(): Argument #1 ($value) must be of type string, XXX given #10069
Closed
@bastien70

Description

@bastien70

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

  1. 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;
    }
}
  1. Create the enum
enum ArticleState: string
{
    case ONLINE = 'online';
    case OFFLINE = 'offline';
}
  1. 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();
    }
  1. 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

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

      0