Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine 2, how to get a property in a left join result set?
    primarykey
    data
    text
    <p>Symfony 2, Doctrine 2.1.</p> <p>I've got 3 entities, one of them intermediate (join table). Let's say it's SomeObject, SomeProperty and ObjectProperties.</p> <p><strong>Problem:</strong> I can't get the value of SomeProperty 'name' property. Here's the code:</p> <pre><code>[...] class SomeObject { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * * @var ObjectProperties $objectProperties * * @ORM\OneToMany(targetEntity="ObjectProperties", mappedBy="object_id", cascade={"all"}) */ private $objectProperties; [...] </code></pre> <hr> <pre><code>[...] class SomeProperty { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\OneToMany(targetEntity="ObjectProperties", mappedBy="property_id", cascade={"all"}) */ private $id; /** * @var string $name * */ private $name;//I NEED TO GET VALUE OF $name [...] </code></pre> <hr> <pre><code>[...] class ObjectProperties { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\ManyToOne(targetEntity="SomeObject", inversedBy="id", cascade={"all"}) * @ORM\JoinColumn(name="object_id", referencedColumnName="id") */ private $object_id; /** * @ORM\Id * @ORM\ManyToOne(targetEntity="SomeProperty", inversedBy="id", cascade={"all"}) * @ORM\JoinColumn(name="property_id", referencedColumnName="id") */ private $property_id; [...] </code></pre> <hr> <p>Setters and getters as usual.</p> <p>In my controller I've got something along the lines of:</p> <pre><code>$entity = $em-&gt;getRepository('SomeTestBundle:SomeObject')-&gt;find($id); [...] $props = $entity-&gt;getObjectProperties(); foreach ($props as $prop){ echo '---------------------------&lt;br&gt;'; var_dump($prop-&gt;getPropertyId()-&gt;getName()); } </code></pre> <hr> <p>Now, getName() gives me null result, but if i replace it with getId it works as expected. Same if I try to use it in a form class. Is it because there is no doctrine association between SomeProperty->name and ObjectProperties?</p> <p>I think I don't quite get the way doctrine is supposed to work. I thought that only property_id and object_id are needed in a junction table, otherwise it doesn't make much sense for me, because SomeProperty serves as a dictionary table, so I could change SomeProperty->name in one place.</p> <p>I'm seriously stuck with it. Is it some sort of configuration option that is lacking or am I generally not getting the bigger picture?</p>
    singulars
    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.
 

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