Symfony表单错误

时间:2017-11-25 12:09:17

标签: symfony

我有3个实体客户端,类,Fournitures。客户与Fournitures有一个OnetoMany关系,Fourniteurs与Classes有ManytoOne关系,为此我为Client表单创建一个nest字段,因为这里是ClientType:

$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');

表单很好但现在问题是在我的newAction中,它返回错误: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"}).

虽然我已经在Fournitures中设置了我的实体类,并且在我的newAction中仍然存在,但问题仍然存在。

/**
 * @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();

        }

我不知道我是否用symfony做了这件事,但我需要帮助解决问题,因为我不知道该怎么做,谢谢!

1 个答案:

答案 0 :(得分:0)

将cascade持久性添加到您的oneToMany关系中。