2014-10-17 17 views
-1

我想創建,根據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; 

} 

錯誤消息:

[Semantical Error] line 0, col 9 near 'rules_id, e.status_id,': Error: Class Ethan\RestBundle\Entity\EthanRules has no field or association named rules_id"

我制定的Symfony 2 FosrestBundle默認名稱與在實體類,但with_underscores在數據庫中創建首字母大寫一個REST應用

+0

顯示EnthanRules實體字段名稱,可能在實體和數據庫中有不同的名稱。例如,如果在實體中您有_public $ rulesId_,那麼您將您的代碼更改爲_e.rulesId_而不是e.rules_id – 2014-10-17 14:34:07

+0

問題不在於計數(*),而是在錯誤中。請更新您的標題 – Aris 2014-10-17 14:58:55

回答

0

主義各個領域。

您需要相應地將您的rules_idstatus_id更改爲rulesstatus

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; 
    } 
} 
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()將是您的最佳選擇,因爲它看起來像你不想處理對象。

+0

@Ali爲您完成了這項工作?如果不告訴我最新的問題。否則,你可以接受這個答案作爲正確的答案 – SBH 2014-10-21 14:39:12

相關問題