我正在嘗試將 id 從一個編隊表傳遞到票證表,但我無法傳遞此錯誤..關聯字段“App\Entity\Ticket#$formation”的“App\Entity\Formation”類型的預期值,取而代之的是“string”。組建實體:/** * @ORM\Entity(repositoryClass="App\Repository\FormationRepository") */class Formation{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="array", nullable=true) */ private $formations = []; /** * @ORM\Column(type="string", length=180, unique=true) */ private $customerName;...票務實體:/** * @ORM\MappedSuperclass() */class Ticket implements TicketInterface{ use Timestampable; /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @ORM\ManyToOne(targetEntity="Symfony\Component\Security\Core\User\UserInterface") * @ORM\JoinColumn(name="author", referencedColumnName="id", nullable=true) */ private $author; /** * @ORM\ManyToOne(targetEntity="App\Entity\Formation") * @ORM\JoinColumn(nullable=false) */ private $formation;...我的ticketControlleraddTicket():public function addTicket(Request $request, TicketManager $ticketManager): Response{ $ticket = $ticketManager->newClass(); $user = $this->getUser(); $formationId = $user->getFormationId()->getId(); $ticketForm = $this->createForm(TicketForm::class, $ticket); $ticketForm->handleRequest($request); if ($ticketForm->isSubmitted() && $ticketForm->isValid()) { $ticketManager->createTicket($user, $ticket, $formationId); $this->addFlash('success', 'Le ticket est en ligne !'); return $this->redirectToRoute('ticketing_list'); } return $this->render($this->ticketingTemplates['new'], [ 'form' => $ticketForm->createView(), ]);}我希望在添加票證時,將“formationId”保存在票證表中。其余的都很好,只有formulaId的注冊不行
1 回答

白衣染霜花
TA貢獻1796條經驗 獲得超10個贊
/**
* @param UserInterface $user
* @param TicketInterface $ticket
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function createTicket(UserInterface $user, TicketInterface $ticket, Formation $formation)
{
$status = $this->ticketStatusManager->getOpenStatus();
$ticket->setStatus($status)->setFormation($formation)->setAuthor($user)->setPublic(false);
if (!$this->isTicketRestrictionEnabled()) {
$ticket->setPublicAt(new \DateTime())->setPublic(true);
}
$this->persistAndFlush($ticket);
}
- 1 回答
- 0 關注
- 154 瀏覽
添加回答
舉報
0/150
提交
取消