Doctrine2 use of criteria inside the entity class
- by Piotr Kowalczuk
They try to write a method whose task would be to return only selected elements of the collection of items associated with a particular entity.
/**
* @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;
}
but i get error:
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
any idea how to fix this?