У меня есть связь OneToMany между доктором сущностей, опытом и парками сущностей. Теперь, когда я пытаюсь сохранить данные своей формы ExperiencesType и ParcoursType, все данные сохраняются, кроме идентификатора доктора.
Entity Doctor
/**
* @ORM\OneToMany(targetEntity="Doctix\MedecinBundle\Entity\Experiences", mappedBy="medecin", cascade={"persist", "remove"})
*/
private $experiences;
/**
* @ORM\OneToMany(targetEntity="Doctix\MedecinBundle\Entity\Parcours", mappedBy="medecin", cascade={"persist", "remove"})
*/
private $parcours;
public function __construct()
{
$this->assurance = new \Doctrine\Common\Collections\ArrayCollection();
$this->experiences = new \Doctrine\Common\Collections\ArrayCollection();
$this->parcours = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get experiences
*
* @return \Doctix\MedecinBundle\Entity\Experiences
*/
public function getExperiences()
{
return $this->experiences;
}
/**
* Get parcours
*
* @return \Doctix\MedecinBundle\Entity\Parcours
*/
public function getParcours()
{
return $this->parcours;
}
Entity Experiences
/**
* @ORM\ManyToOne(targetEntity="Doctix\MedecinBundle\Entity\Medecin", inversedBy="experiences")
* @ORM\JoinColumn(name="medecin_id", referencedColumnName="id" , nullable=true)
*/
private $medecin;
/**
* Set medecin
*
* @param \Doctix\MedecinBundle\Entity\Medecin $medecin
*
* @return Experiences
*/
public function setMedecin(\Doctix\MedecinBundle\Entity\Medecin $medecin = null)
{
$this->medecin = $medecin;
return $this;
}
/**
* Get medecin
*
* @return \Doctix\MedecinBundle\Entity\Medecin
*/
public function getMedecin()
{
return $this->medecin;
}
Entic Parcours
/**
* @ORM\ManyToOne(targetEntity="Doctix\MedecinBundle\Entity\Medecin", inversedBy="parcours")
* @ORM\JoinColumn(name="medecin_id", referencedColumnName="id")
*/
private $medecin;
/**
* Set medecin
*
* @param \Doctix\MedecinBundle\Entity\Medecin $medecin
*
* @return Parcours
*/
public function setMedecin(\Doctix\MedecinBundle\Entity\Medecin $medecin = null)
{
$this->medecin = $medecin;
return $this;
}
/**
* Get medecin
*
* @return \Doctix\MedecinBundle\Entity\Medecin
*/
public function getMedecin()
{
return $this->medecin;
}
Тогда это моя форма: MedecinCvEditType
class MedecinCvEditType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->remove('user')
->remove('specialite')
->add('experiences', CollectionType::class, array(
'entry_type' => ExperienceType::class,
'allow_add' => true,
'allow_delete' => true
))
->add('parcours', CollectionType::class, array(
'entry_type' => ParcoursType::class,
'allow_add' => true,
'allow_delete' => true
));
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Doctix\MedecinBundle\Entity\Medecin'
));
}
}
Наконец, мой контроллер:
Контроллер
public function cvEditAction(Request $request)
{
$user = $this->getUser();
if ($user === null) {
throw new NotFoundHttpException('Utilisateur Inexistant');
} else {
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('DoctixMedecinBundle:Medecin');
$medecin = $repo->findOneBy(array(
'user' => $user,
));
$form = $this->createForm('Doctix\MedecinBundle\Form\MedecinCvEditType', $medecin);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em->flush();
// creation d'un flash bag pour une notification flash
$request->getSession()->getFlashBag()->add('Notice', 'Cv Modifié avec succés');
// redirection
$url = $this->generateUrl('medecin_parametre');
// redirection permanente avec le status http 301 ::)))))
return $this->redirect($url, 301);
} else {
return $this->render('DoctixMedecinBundle:Medecin:cvedit.html.twig', array(
'form' => $form->createView()
));
}
}
}
Это скриншоты моей базы данных:
Спасибо