How to filter getter in doctrine2 object?

I have an entity that has a one-to-many association (many-to-many with extra fields):

class Game { /** /* @OneToMany(targetEntity="GamePlayer", mappedBy="game", cascade={"persist"}) /* @JoinColumn(name="id", referencedColumnName="game_id", onDelete="cascade") */ private $gamePlayer; } 

The class has an automated getter for all authors: getGamePlayers ()

I would like to add a filter to it, so it will only query the database for the relevant details in the most efficient way:

 public function getGamePlayersWithScoreHigherThan($score){ //what to write here? (return array) } 

What is the best way to get such a getter from within an object (without using a repository)?

Many thanks!

+7
source share
1 answer

You can try creating a separate method for your entity that uses Doctrine \ Common \ Collections \ Criteria to filter the associated collection. See this link for details.

+4
source

All Articles