-1

I have a problem with a many to one relationship.

Here I have a Client entity that already exists. Then I try to link Documents to this entity.

I have a document creation form with a selector that lists my clients. There are no problems.

But when I try to record my dcoument I have the following message:

A new entity was found through the relationship 'App\Entity\Document#Client' that was not configured to cascade persist operations for entity: App\Entity\Client@000000006889f4d900000000795bd53c. 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"}). If you cannot find out which entity causes the problem implement 'App\Entity\Client#__toString()' to get a clue.

I do not understand why I must persit my client entity.

In my document entity I have this:

 /**
 * @ORM\ManyToOne(targetEntity="App\Entity\Client", inversedBy="Documents")
 * @ORM\JoinColumn(nullable=false)
 */
private $Client;

And in my Client entity I have this:

/**
 * @ORM\OneToMany(targetEntity="App\Entity\Document", mappedBy="Client")
 * @ORM\JoinColumn(nullable=false)
 */
private $Documents;

Do you have any idea about the nature of my problem?

Thank you in advance.

DonCallisto
  • 29,419
  • 9
  • 72
  • 100
wehtam
  • 39
  • 3
  • 2
    Possible duplicate of [Doctrine - A new entity was found through the relationship](https://stackoverflow.com/questions/18215975/doctrine-a-new-entity-was-found-through-the-relationship) – Mike Doe Jul 25 '19 at 13:18

1 Answers1

0

Change

 /**
 * @ORM\ManyToOne(targetEntity="App\Entity\Client", inversedBy="Documents")
 * @ORM\JoinColumn(nullable=false)
 */
private $Client;

to

 /**
 * @ORM\ManyToOne(targetEntity="App\Entity\Client", inversedBy="Documents", cascade={"persist"})
 * @ORM\JoinColumn(nullable=false)
 */
private $Client;
DonCallisto
  • 29,419
  • 9
  • 72
  • 100
  • now i have this error : Notice: Undefined index: 0000000021c853f2000000000f9ea414 – wehtam Jul 25 '19 at 13:25
  • @wehtam Please, provide more details (like exception stack trace). – DonCallisto Jul 25 '19 at 13:27
  • ErrorException: Notice: Undefined index: 000000003d39d146000000006d27e6db at vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php:2997 at Doctrine\ORM\UnitOfWork->getEntityIdentifier(object(ModePaiement)) (vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php:677) at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->prepareUpdateData(object(Client)) (vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php:713) at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->prepareInsertData(object(Client)) – wehtam Jul 25 '19 at 13:54