2012-11-18 28 views
1

我嘗試編寫一個方法,其任務是僅返回與特定實體關聯的項集合中的選定元素。Doctrine2在實體類中使用條件

/** 
* @ORM\OneToMany(targetEntity="PlayerStats", mappedBy="summoner") 
* @ORM\OrderBy({"player_stat_summary_type" = "ASC"}) 
*/ 
protected $player_stats; 

public function getPlayerStatsBySummaryType($summary_type) 
{ 
    if ($this->player_stats->count() != 0) { 
     $criteria = Criteria::create() 
      ->where(Criteria::expr()->eq("player_stat_summary_type", $summary_type)); 

     return $this->player_stats->matching($criteria)->first(); 
    } 

    return null; 
} 

,但我得到的錯誤:

PHP Fatal error: Cannot access protected property Ranking\CoreBundle\Entity\PlayerStats::$player_stat_summary_type in /Users/piotrkowalczuk/Sites/lolranking/vendor/doctrine/common/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php on line 53 

任何想法如何解決這一問題?

回答

2

固定。它應該是:

$criteria = Criteria::create() 
     ->where(Criteria::expr()->eq("playerStatSummaryType", $summary_type)); 
1

確保PlyerStats實體具有getPlayerStatSummaryType()公共方法。它由@ORM\OrderBy註釋使用,並且(我想)由您在getPlayerStatsBySummaryType()內的自定義標準使用。

0

Ranking\CoreBundle\Entity\PlayerStats類中爲$player_stat_summary_type屬性提供吸氣劑。