2017-11-25 4 views
0

Ich habe 3 Entity Client, Klassen, Fournitures. Client hat eine OneToMany Beziehungen zu Fournitures und Fourniteurs hat eine ManytoOne Beziehungen zu Klassen, dies zu tun, ich mache ein Nest Felder für die Client-Form wie hier ist die Client:Symfony Form Fehler

$builder->add('nom') 
    ->add('adresse') 
    ->add('idfournitures', FournituresType::class); 

FournituresType

$builder->add('nom') 
    ->add('value') 
    ->add('prix') 
    ->add('idclasses', ClassesType::class); 

ClassesType

$builder->add('categories') 
    ->add('famille'); 

die Form ist in Ordnung, aber das Problem ist nun, dass während meiner NewAction, den Fehler zurückgibt: A new entity was found through the relationship 'AppBundle\Entity\Fournitures#idclasses' that was not configured to cascade persist operations for entity. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}).

und obwohl ich bereits meine Entity Klassen mit Kaskade in Fournitures beibehalten habe und auch in meiner newAction beibehalten wurde, besteht das Problem immer noch.

/** 
* @var \AppBundle\Entity\Classes 
* 
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Classes", cascade={"persist"}) 
* @ORM\JoinColumns({ 
* @ORM\JoinColumn(name="idclasses", referencedColumnName="idclasses", nullable=false) 
* }) 
*/ 
private $idclasses; 

NewAction

if ($form->isSubmitted() && $form->isValid()) { 

     $em->persist($client); 
     $em->persist($client->getIdfournitures()); 
     $em->persist($client->getIdfournitures()->getIdclasses()); 
     $em->flush(); 

     } 

Ich weiß nicht, ob das, was ich mit symfony dies zu tun bin oder nicht, aber ich brauche, um das Problem zu lösen, weil ich nicht weiß, was Sie zu tun, danke !

+0

Können Sie Ihre gesamte newAction() posten –

Antwort

0

Fügen Sie die cascade persist auch zu Ihrer oneToMany-Beziehung hinzu.