我正在尝试将 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的注册不行
白衣染霜花