Reputation: 399
I 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?
Upvotes: 1
Views: 3165
Reputation: 399
Fixed. It should be:
$criteria = Criteria::create()
->where(Criteria::expr()->eq("playerStatSummaryType", $summary_type));
Upvotes: 2
Reputation: 22820
Provide a getter for $player_stat_summary_type
property in Ranking\CoreBundle\Entity\PlayerStats
class.
Upvotes: 0
Reputation: 48477
Ensure that PlyerStats
entity has getPlayerStatSummaryType()
public method. It's being used by the @ORM\OrderBy
annotation and (I suppose) by you custom criteria inside getPlayerStatsBySummaryType()
.
Upvotes: 1