0
我經歷了所有類似的問題,但似乎沒有任何東西可以解決我的問題。 我已經在我的MatchRepository中添加了一個簡單的查詢,但它引發了語義錯誤。語義錯誤:類MailileoBundle Entity Match沒有字段或關聯名爲getMailid
我有雙(三重)檢查我的實體,一切都很好。它甚至可以正常工作,當我通過findAll()全部匹配並運行$ match-> getMailid() 問題只出現在MatchRepository文件中。
下面的代碼:
實體:
<?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;
}
}
這裏的倉庫:
<?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;
}
}
,我通過運行這個:
$dbb = $this->container->get('doctrine.orm.entity_manager');
$match = $dbb->getRepository('MailileoBundle:Match')->findMatchForMailId($mailid);
這裏是我的到目前爲止已經嘗試過: - 清除緩存 - 通過控制檯 更新實體/ DB模式 - 重新啓動服務器 - 使用q.mailid代替getMailid
的我使用symfony3。
任何建議?謝謝!!!
用q.mailid替換q.getMailid。 DQL對getter/setter一無所知。 – Cerad
嗯,似乎是工作。我想知道,因爲在我的用戶儲存庫我有getters在SQL查詢,他們工作正常。那可能是因爲AdvancedUserInterface類嗎? – Konrad