Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Entity
- */
- class Category extends Nette\Object
- {
- /**
- * @OneToMany(targetEntity="Article", mappedBy="highlightedIn")
- */
- private $highlighted;
- /**
- * @OneToMany(targetEntity="Article", mappedBy="category")
- */
- private $articles;
- public function getArticles()
- {
- return $this->articles->toArray();
- }
- public function getHighlighted()
- {
- return $this->highlighted->toArray();
- }
- }
- /**
- * @Entity
- */
- class Article extends Nette\Object
- {
- /**
- * @ManyToOne(targetEntity="Category", inversedBy="highlighted")
- */
- private $highlightedIn;
- /**
- * @ManyToOne(targetEntity="Category", inversedBy="articles")
- */
- private $category;
- public function setCategory(Category $category)
- {
- $this->category = $category;
- // $category->articles->add($this);
- }
- public function setHighlighted(Category $category)
- {
- $this->highlightedIn = $category;
- // $category->highlighted->add($this);
- }
- }
- $category = new Category();
- $fooArticle = new Article();
- $fooArticle->setCategory($category);
- $barArticle = new Article();
- $barArticle->setCategory($category);
- $barArticle->setHighlighted($category);
- // ...
- $category->getArticles() // foo, bar
- $category->getHighlighted() // bar
Advertisement
Add Comment
Please, Sign In to add comment