I went through all similar issues but nothing appears to solve my problem.
I've put a simple query in my MatchRepository
but it throws a semantic error.
I've double(triple) checked my entity and everything looks fine. It even works fine when I pull all Matches via findAll()
and then run a $match->getMailid()
The problem appears only in the MatchRepository
file.
Here's the code:
Entity:
<?php
namespace MailileoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use MailileoBundle\Modules\DatabaseController;
use MailileoBundle\Entity\QueueItem;
use MailileoBundle\Entity\Message;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Table(name="matches")
* @ORM\Entity(repositoryClass="MailileoBundle\Entity\MatchRepository")
*/
class Match
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="QueueItem", mappedBy="match")
*/
private $queueItems;
/**
* @ORM\OneToMany(targetEntity="Message", mappedBy="match")
*/
private $messages;
/**
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @ORM\Column(type="string", length=15)
*/
private $mailid;
/**
* @ORM\Column(name="deleted", type="boolean")
*/
private $deleted;
/**
* Get id
*
* @return integer
*/
public function __construct($items, $mailid) {
foreach ($items as $item) {
$this->queueItems[] = $item;
}
$this->mailid = $mailid;
$this->created = new \DateTime("now");
$this->deleted = false;
}
public function getId()
{
return $this->id;
}
/**
* Set matchtwo
*
* @param string $matchtwo
*
* @return Match
*/
/**
* Set created
*
* @param \DateTime $created
*
* @return Match
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set mailid
*
* @param string $mailid
*
* @return Match
*/
public function setMailid($mailid)
{
$this->mailid = $mailid;
return $this;
}
/**
* Get mailid
*
* @return string
*/
public function getMailid()
{
return $this->mailid;
}
/**
* Set deleted
*
* @param boolean $deleted
*
* @return Match
*/
public function setDeleted($deleted)
{
$this->deleted = $deleted;
return $this;
}
/**
* Get deleted
*
* @return boolean
*/
public function getDeleted()
{
return $this->deleted;
}
/**
* Add queueItem
*
* @param \MailileoBundle\Entity\QueueItem $queueItem
*
* @return Match
*/
public function addQueueItem(\MailileoBundle\Entity\QueueItem $queueItem)
{
$this->queueItems[] = $queueItem;
return $this;
}
/**
* Remove queueItem
*
* @param \MailileoBundle\Entity\QueueItem $queueItem
*/
public function removeQueueItem(\MailileoBundle\Entity\QueueItem $queueItem)
{
$this->queueItems->removeElement($queueItem);
}
/**
* Get queueItems
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getQueueItems()
{
return $this->queueItems;
}
/**
* Add message
*
* @param \MailileoBundle\Entity\Message $message
*
* @return Match
*/
public function addMessage(\MailileoBundle\Entity\Message $message)
{
$this->messages[] = $message;
return $this;
}
/**
* Remove message
*
* @param \MailileoBundle\Entity\Message $message
*/
public function removeMessage(\MailileoBundle\Entity\Message $message)
{
$this->messages->removeElement($message);
}
/**
* Get messages
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getMessages()
{
return $this->messages;
}
}
Here's the repository:
<?php
namespace MailileoBundle\Entity;
/**
* MatchRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class MatchRepository extends \Doctrine\ORM\EntityRepository
{
public function findMatchForMailId($mailid) {
$query = $this->getEntityManager()->createQuery("SELECT q FROM MailileoBundle:Match as q WHERE q.getMailid = :mailid")->setParameter('mailid', $mailid);
$item = $query->getOneOrNullResult();
return $item;
}
}
and I'm running this via:
$dbb = $this->container->get('doctrine.orm.entity_manager');
$match=$dbb->getRepository('MailileoBundle:Match')->findMatchForMailId($mailid);
Here's what I've tried so far:
q.mailid
instead of getMailid()
I'm using symfony3.
Any advices? Thanks!!!
OK as Cerad had suggested I should use a property name not a getter.