我想根据e.rules_id创建一个恢复号码的请求,e.status_id
public function findStat()
{
$types = $this->em
->getRepository('EthanRestBundle:EthanRules')
->createQueryBuilder('e')
->select('e.rules_id, e.status_id, COUNT(*)')
->groupBy('e.rules_id, e.status_id')
->orderBy('rules_id');
$types = $types->getQuery()->getSingleScalarResult();
return $types;
}
错误消息:
[语义错误]第0行,第9行附近' rules_id,e.status_id,':错误:类Ethan \ RestBundle \ Entity \ EthanRules没有名为rules_id的字段或关联"
我使用FosrestBundle在Symfony 2上开发以创建REST应用程序
答案 0 :(得分:0)
默认情况下,Doctrine在实体类中使用camelCase命名所有字段,但在数据库中使用with_underscores命名。
您需要相应地将rules_id
和status_id
更改为rules
和status
。
答案 1 :(得分:0)
namespace Ethan\RestBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* EthanRules
*
* @ORM\Table(name="ethan_rules")
* @ORM\Entity
*/
class EthanRules
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="customer_key", type="string", length=45, nullable=false)
*/
private $customerKey;
/**
* @var string
*
* @ORM\Column(name="subscription_key", type="string", length=45, nullable=true)
*/
private $subscriptionKey;
/**
* @var string
*
* @ORM\Column(name="pole", type="string", length=45, nullable=false)
*/
private $pole;
/**
* @var string
*
* @ORM\Column(name="link_number", type="string", length=255, nullable=false)
*/
private $linkNumber;
/**
* @var string
*
* @ORM\Column(name="user", type="string", length=100, nullable=true)
*/
private $user;
/**
* @var \DateTime
*
* @ORM\Column(name="date_rdv", type="datetime", nullable=true)
*/
private $dateRdv;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
private $updatedAt;
/**
* @var \Rules
*
* @ORM\ManyToOne(targetEntity="Rules")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="rules_id", referencedColumnName="id")
* })
*/
private $rules;
/**
* @var \Status
*
* @ORM\ManyToOne(targetEntity="Status")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="status_id", referencedColumnName="id")
* })
*/
private $status;
public function _construct()
{
$this->createdAt = new \DateTime();
$this->createdAt->setTimestamp(time());
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set customerKey
*
* @param string $customerKey
* @return EthanRules
*/
public function setCustomerKey($customerKey)
{
$this->customerKey = $customerKey;
return $this;
}
/**
* Get customerKey
*
* @return string
*/
public function getCustomerKey()
{
return $this->customerKey;
}
/**
* Set subscriptionKey
*
* @param string $subscriptionKey
* @return EthanRules
*/
public function setSubscriptionKey($subscriptionKey)
{
$this->subscriptionKey = $subscriptionKey;
return $this;
}
/**
* Get subscriptionKey
*
* @return string
*/
public function getSubscriptionKey()
{
return $this->subscriptionKey;
}
/**
* Set pole
*
* @param string $pole
* @return EthanRules
*/
public function setPole($pole)
{
$this->pole = $pole;
return $this;
}
/**
* Get pole
*
* @return string
*/
public function getPole()
{
return $this->pole;
}
/**
* Set linkNumber
*
* @param string $linkNumber
* @return EthanRules
*/
public function setLinkNumber($linkNumber)
{
$this->linkNumber = $linkNumber;
return $this;
}
/**
* Get linkNumber
*
* @return string
*/
public function getLinkNumber()
{
return $this->linkNumber;
}
/**
* Set user
*
* @param string $user
* @return EthanRules
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return string
*/
public function getUser()
{
return $this->user;
}
/**
* Set dateRdv
*
* @param \DateTime $dateRdv
* @return EthanRules
*/
public function setDateRdv($dateRdv)
{
$this->dateRdv = $dateRdv;
return $this;
}
/**
* Get dateRdv
*
* @return \DateTime
*/
public function getDateRdv()
{
return $this->dateRdv;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return EthanRules
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
* @return EthanRules
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set rules
*
* @param \Ethan\RestBundle\Entity\Rules $rules
* @return EthanRules
*/
public function setRules(\Ethan\RestBundle\Entity\Rules $rules = null)
{
$this->rules = $rules;
return $this;
}
/**
* Get rules
*
* @return \Ethan\RestBundle\Entity\Rules
*/
public function getRules()
{
return $this->rules;
}
/**
* Set status
*
* @param \Ethan\RestBundle\Entity\Status $status
* @return EthanRules
*/
public function setStatus(\Ethan\RestBundle\Entity\Status $status = null)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* @return \Ethan\RestBundle\Entity\Status
*/
public function getStatus()
{
return $this->status;
}
}
答案 2 :(得分:0)
由于您尚未定义属性$rules_id
,因此不能选择一个属性。而是加入两个实体并选择它们的ID:
$types = $this->em
->getRepository('EthanRestBundle:EthanRules')
->createQueryBuilder('e')
->select('r.id AS rule_id, s.id AS status_id, COUNT(DISTINCT e.id)')
->leftJoin('e.rules', 'r')
->leftJoin('e.status', 's')
->groupBy('r.id, s.id')
->orderBy('r.id');
但是:您使用的getSingleScalarResult()
不适用于多个结果行!
对你来说,getArrayResult()
是最好的选择,因为看起来你不想使用对象。