Symfony& Doctrine外键参考

时间:2016-04-23 13:45:43

标签: php doctrine-orm foreign-keys symfony

我的外键有问题。

记录

Uncaught PHP Exception Doctrine\ORM\ORMInvalidArgumentException: "Expected value of type "GuideBundle\Entity\Actors" for association field "GuideBundle\Entity\MedicalStaff#$actorId", got "integer" instead." at D:\Elya\КПИ\6 семестр\TSPP\mg\vendor\doctrine\orm\lib\Doctrine\ORM\ORMInvalidArgumentException.php line 206  []

MedicalStaff实体

    /**
     * @ORM\OneToOne(targetEntity="Actors")
     * @ORM\JoinColumn(name="actorId", referencedColumnName="id")
     */
    private $actorId;

演员实体

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

MedicalStaffController

/**
     * Creates a new MedicalStaff entity.
     *
     * @Route("/new", name="admin_new")
     * @Method({"GET", "POST"})
     */
    public function newAction(Request $request)
    {
        $medicalStaff = new MedicalStaff();
        $actor = new Actors();
        $form = $this->createForm('GuideBundle\Form\MedicalStaffType', $medicalStaff);
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $actor->setRole(2);
            $em = $this->getDoctrine()->getManager();
            $em->persist($actor);
            $em->flush();
            $medicalStaff->setActorId($actor->getId()); //problem
            $em->persist($medicalStaff); //is
            $em->flush(); //here
            //$this->generateLogin($medicalStaff->getActorId(), $medicalStaff->getEmail());
            $flash = $this->get('braincrafted_bootstrap.flash');
            $flash->success('Succesfully registered.');
        }
        return $this->render('medicalstaff/new.html.twig', array(
            'medicalStaff' => $medicalStaff,
            'form' => $form->createView(),
        ));
    }

也许我没有正确使用FK参考。我需要将MedicalStaff.actorId设置为与

上面插入的Actor.id相同

0 个答案:

没有答案