I have this model:
class Article {
protected $id;
protected $title;
protected $author;
protected $datetime;
protected $games;
public function __construct() {
$this->datetime = new DateTime();
$this->games = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId() { return $this->id; }
public function setTitle($v) { $this->title = $v; }
public function getTitle() {
if(empty($this->title)) {
$game = $this->getFirstGame();
return ($game instanceof Game) ? $game->getTitle() : NULL;
} else
return $this->title;
}
public function setAuthor($v) { $this->author = $v; }
public function getAuthor() { return $this->author; }
public function getDateTime() { return $this->datetime; }
public function setDateTime($v) { $this->datetime = $v; }
public function setGames($value) {
$except_txt = 'Jedna z przesłanych wartości nie jest instancją klasy Game!';
if(is_array($value)) {
foreach($value as $v) {
if($v instanceof Game) $this->games->add($v);
else throw new Exception($except_txt);
}
} else {
if($value instanceof Game) $this->games->add($value);
else throw new Exception($except_txt);
}
}
public function getGames() { return $this->games; }
}
How to make a request look like
SELECT a FROM Article a WHERE :game_id IN a.games
I have it ( $game->getId()- an integer)
$articles = $db->createQuery("SELECT a.type FROM Article a WHERE :game_id IN a.games GROUP BY a.type")->setParameter('game_id', $game->getId())->getResult();
But it returns me a syntax error
[Syntax Error] line 0, col 47: Error: Expected Doctrine\ORM\Query\Lexer::T_OPEN_PARENTHESIS, got 'a'
source
share