Symfony 4 - EntityType - 加载当前值

Symfony 4 - EntityType - Load current value

我在 Symfony 4 的 formType 中使用 EntityType。当我以新形式显示它时一切正常,choicetype 列表包含我数据库中的所有值。但是当我从我的数据库中加载现有数据时,选择列表不会从数据库中加载值,它会显示占位符。我已经检查了数据库并保存了值。我的表格看起来像这样

->add('operatingSystem', EntityType::class, [
                 'class' => "App\Entity\TicketOperatingSystem",
                 'choice_label' => 'name',
                 'label'    => 'Système d\'exploitation',
                 'required' => false,
             ])

实体:

/**
 * @ORM\ManyToOne(targetEntity="Maps_red\TicketingBundle\Entity\TicketOperatingSystem")
 * @ORM\JoinColumn(name="operating_system", referencedColumnName="id", nullable=true)
 */
private $operatingSystem;

public function getOperatingSystem(): ?TicketOperatingSystemInterface
{
    return $this->operatingSystem;
}

public function setOperatingSystem(?TicketOperatingSystemInterface $ticketOperatingSystem): UserInstance
{
    $this->operatingSystem = $ticketOperatingSystem;

    return $this;
}

操作系统实体:

/**
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $id;

/**
 * @ORM\Column(type="string", length=255)
 */
private $name;

public function getId() : ?int
{
    return $this->id;
}

public function getName(): ?string
{
    return $this->name;
}

public function setName(string $name): TicketOperatingSystemInterface
{
    $this->name = $name;

    return $this;
}

为了测试,我尝试将 EntityType 更改为列表为 2 的 ChoiceType,它运行良好。我不知道 EntityType 的问题是什么。

尝试添加 'choice_value' => 'name',

  ->add('operatingSystem', EntityType::class, [
             'class' => "App\Entity\TicketOperatingSystem",
             'choice_label' => 'name',
             'choice_value' => 'name',
             'label'    => 'Système d\'exploitation',
             'required' => false,
         ])