0

I have an issue with my query if when I have this following setup.

I have an entity

<?php
class EntityB 
{
     /**
      * @ORM\ManyToOne(targetEntity="EntityA", inversedBy="someKeyWord")
      * @ORM\JoinColumn(name="entityA_id", referencedColumnName="id")
      */
     private $entityA;
}

Now when you query and get an array as result, it works

// EntityBRepository.php
public function querySomeStuff($isArray=false)
{
    $b = $entityManager->createQuery('
        SELECT partial eA.{id, title}
        FROM EntityB eB
        LEFT JOIN eB.entityA eA
    ');

    if ($isArray) {
        $r = $b->getArrayResult();
    } else {
        $r = $b->getResult();
    }

    if (count($r)) {
        return $r[0];
    } else {
        return null;
    }
}

But if I do the same function call but pass the 2nd parameter as false, meaning, I don't want to get the result as an array, it crashes saying Notice: Undefined index: someKeyWord.

This is related to doctrine inversedBy mapping with partial left join query.

  • This is not the same as what posted on the supposed to be duplicate post. This is more related to doctrine's inversedBy mapping. – M.Elmonian Feb 18 '18 at 01:17
  • Your question is still not well constructed. Lay out the problem before the sharing the code. Beyond the ["How to ask"](https://stackoverflow.com/help/how-to-ask) advice, you also need to start by stating the question in a way that focuses on what gap remains _after_ your research. Then describe your strategy thus far, code setup + conditions, and the errors/issues. Also state 'obvious' context that you already know, so that people understand what you have tried. See also [1](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/), [2](https://stackoverflow.com/help/mcve) – New Alexandria Feb 18 '18 at 04:30

0 Answers0