I have a Symfony 2.4.x project.
In there, I have two entities that are mapped together: Conference and Paper.
Each conference has papers and with a specific conference, I would like to get the number of papers.
For that, in my conference entity, I have:
/**
* @ORM\OneToMany(targetEntity="Paper", mappedBy="conference")
*/
protected $papers;
In the entity Paper 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 well, but now I migrated it in Symfony 2.4.x and I am getting the following error when trying to do:
count($conf->getPapers()); // In the controller
{{ conf.papers | length }} // In the twig template
Error:
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 the two entities in pastebin:
EDIT 2: Here are some news that I found by trying to solve the problem. Another classe is involved there: Submission.
Here is the code: http://pastebin.com/bkdRtjdq
In the class Submission, I have the primary key that is hash_key and not the id.
I had the same error when I was trying to get entities with ObjectManager
in ManyToMany
realtionship:
$repository->findBy(
array('members' = > $user)
);
My workaround was to write 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.
I would guess it could be caused by the plural case: papers
Try this:
/**
* @ORM\OneToMany(targetEntity="Paper", mappedBy="conference")
*/
protected $paper;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With