I have two classes:
The game
class Game { protected $id; protected $title; protected $news; public function __construct() { $this->news = new \Doctrine\Common\Collections\ArrayCollection(); } public function getId() { return $this->id; } public function setTitle($val) { $this->title = trim($val); } public function getTitle() { return $this->title; } public function getNews() { return $this->news; } public function setNews($value) { $except_txt = 'Jedna z przesłanych wartości nie jest instancją klasy News!'; if(is_array($value)) { foreach($value as $v) { if($v instanceof News) $this->news->add($v); else throw new Exception($except_txt); } } else { if($value instanceof News) $this->news->add($value); else throw new Exception($except_txt); } } }
news
class News { protected $id; protected $title; protected $content; protected $author; protected $add_date; protected $games; public function __construct() { $this->add_date = new DateTime(); $this->games = new \Doctrine\Common\Collections\ArrayCollection(); }
And this code:
$i = 1; if($game->getNews()->count() > 0) { foreach($game->getNews()->getValues() as $v) { $news_list.= '<p>News '.$i.'</p>'; $i++; if($i == 6) break; } }
1st question : Does Doctrine will download from the database all the news related to a particular game, or only the 5 that I need?
Second question : How can I download 5 news with a separate Doctrine doctor without the NewsGames class?
source share