Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine 2. How to force entity from proxy
    primarykey
    data
    text
    <p>I have 3 entities:</p> <pre><code>/** * @ORM\Entity * @ORM\Table(name="table_a") */ class A { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue */ protected $id; /** * ORM\OneToMany(targetEntity="B", mappedBy="entityA") */ protected $entitiesB; /** * ORM\OneToMany(targetEntity="C", mappedBy="entityA") */ protected $entitiesC; /** * @ORM\Column(type="string") */ protected $name; } /** * @ORM\Entity * @ORM\Table(name="table_b") */ class B { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue */ protected $id; /** * ORM\ManyToOne(targetEntity="A", inversedBy="entitiesB") */ protected $entityA; /** * @ORM\Column(type="date") */ protected $date; } /** * @ORM\Entity * @ORM\Table(name="table_c") */ class C { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue */ protected $id; /** * ORM\ManyToOne(targetEntity="A", inversedBy="entitiesC") */ protected $entityA; /** * @ORM\Column(type="string") */ protected $description; } </code></pre> <p>And I have the following situation:</p> <pre><code>$eB = $repositoryB-&gt;find(1); $eA = $eB-&gt;getEntityA(); // $eA will be a proxy $eC = new C(); $eC-&gt;setDescription('XXXXXXXXXX') -&gt;setEntityA($eA); </code></pre> <p>This will generate an error because $eA is a proxy not an entity. Even if I try:</p> <pre><code>$eB = $repositoryB-&gt;find(1); $eA = $repositoryA-&gt;find(1); $eC = new C(); $eC-&gt;setDescription('XXXXXXXXXX') -&gt;setEntityA($eA); </code></pre> <p>Will still get an error because once you have fetched a B entity it will automatically fetch a proxy of A entity. And when you try to fetch the A entity with the same identifier as the proxy Doctrine will return the proxy object from the Identity Map because you can not have two objects (one proxy and one Entity) for the same db record.</p> <p>So is there a way to force retrieving an entity from its proxy? Or another way to set an association, by id not by entity?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload