Doctrine2 use of criteria inside the entity class

Posted by Piotr Kowalczuk on Stack Overflow See other posts from Stack Overflow or by Piotr Kowalczuk
Published on 2012-11-18T10:57:03Z Indexed on 2012/11/18 10:59 UTC
Read the original article Hit count: 310

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about symfony2