0

I have Zend Framework 3 + Doctrine ORM application.

   Class Goods have link "characters":

    /**
     * Goods
     *
     * @ORM\Entity
     * @ORM\Table(name="goods")
     * @property int $id
     */
    class Goods implements InputFilterAwareInterface
    {
          /**
     * @ORM\ManyToMany(targetEntity="\Application\Entity\CharacterValue", inversedBy="goods")
     * @ORM\JoinTable(name="character_value_item",
     *   joinColumns={@ORM\JoinColumn(name="good_id", referencedColumnName="id")},
     *   inverseJoinColumns={@ORM\JoinColumn(name="value_id", referencedColumnName="id")})
     **/

       protected $characters;

   public function getCharacters()
   {
      return $this->characters;
   }
  }

I trying to use this method to get characters by method for lazy loading, but it returns just one character. Not all characters for the product.

$dql = 'SELECT u, ch FROM Goods u LEFT JOIN u.characters ch';

This method from here:

$query = $em->createQuery('SELECT u, p FROM CmsUser u JOIN u.phonenumbers p');
$users = $query->getResult(); // array of CmsUser objects with the phonenumbers association loaded
$phonenumbers = $users[0]->getPhonenumbers();

https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/dql-doctrine-query-language.html#dql-select-examples

I do not understand why documentation's method working wrong. What is the right way to deside my issue?

  • It should work, try to force a refresh of the query results, $query->setHint(Query::HINT_REFRESH, true); as described https://stackoverflow.com/questions/48152609/doctrine-onetomany-relation-all-result-row-doesnt-fetch-in-object/48510697#48510697 Also include getCharacters() method. – Jannes Botis Feb 20 '20 at 12:12
  • Added getCharacters() function to the question. Thank you, I was trying $query->setHint(Query::HINT_REFRESH, true). Same result. If I add "ch" in the SELECTpart, than getCharacters() returns ONE element. Not all characters. – Илья Шах Feb 21 '20 at 13:24

0 Answers0