Orphan in OneToOne relation

50 views Asked by At

I have a relation in database (customer -> address).

In my case :

  • customer has an address_id (not null)
  • address (table) has been removed

I have defined my models as follow

  • Customer
<?php

namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
*/
class Customer
{

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

/**
* @ORM\OneToOne(targetEntity="App\Entity\Address", orphanRemoval=true)
* @ORM\JoinColumns({
*   @ORM\JoinColumn(name="address_id", referencedColumnName="id")
* })
*/
private $address;
  • Address
<?php

namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\AddressRepository")
 */
class Address
{

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

}

With this I have the following message :

Entity of type 'App\Entity\Address' for IDs id(10) was not found

What should I do for orphan (here address) be ignored ?

0

There are 0 answers