Symfony2 and Doctrine - Undefined index

I have a symfony 2.4.x project.

It has two objects that appear together: Conference and Paper.

In each conference there are documents and with a special conference, I would like to receive the number of documents.

For this, in my conference organization, I:

/** * @ORM\OneToMany(targetEntity="Paper", mappedBy="conference") */ protected $papers; 

In the document of the document that I have:

 /** * @ORM\ManyToOne(targetEntity="Conference", inversedBy="papers") * @ORM\JoinColumn(name="conference_id", referencedColumnName="id") */ protected $conference; 

When I had this project on Symfony2.0, everything worked fine, but now I ported it to Symfony 2.4.x, and when trying to do the following:

 count($conf->getPapers()); // In the controller {{ conf.papers | length }} // In the twig template 

Mistake:

 ContextErrorException: Notice: Undefined index: hash_key in /var/www/git/conference2.0-v2.4/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php line 121 

EDIT: Here are the full classes of two objects in pastebin:

EDIT 2: Here are some news I found trying to solve a problem. There is another class involved: Performance.

Here is the code: http://pastebin.com/bkdRtjdq

In the class view, I have a hash_key primary key, not an id.

+7
php symfony entity twig doctrine2
source share
3 answers

I had the same error when I tried to get objects with ObjectManager in ManyToMany realtionship:

 $repository->findBy( array('members' = > $user) ); 

My workaround was to write the find method in Repository with DQL:

 public function findByMember(User $member) { $qb = $this->createQueryBuilder('g'); $qb->innerJoin('g.members', 'wg') ->where($qb->expr()->eq('wg', ':member')) ->setParameter('member', $member); return $qb->getQuery()->getResult(); } 

Maybe it will be useful for someone.

+1
source share

Are there cases where documents are 0? The conf.papers variable can be null, and you will need to check if it is null before counting. {% if conf.papers is empty%} ... {% endif%}

0
source share

I suppose this could be caused by a multiple case: paper s

Try the following:

 /** * @ORM\OneToMany(targetEntity="Paper", mappedBy="conference") */ protected $paper; 
0
source share

All Articles