3 namespace Doctrine\Tests\Models\ECommerce;
5 use Doctrine\Common\Collections\ArrayCollection;
9 * Represents a tag applied on particular products.
11 * @author Giorgio Sironi
13 * @Table(name="ecommerce_categories")
15 class ECommerceCategory
18 * @Id @Column(type="integer")
19 * @GeneratedValue(strategy="AUTO")
24 * @Column(type="string", length=50)
29 * @ManyToMany(targetEntity="ECommerceProduct", mappedBy="categories")
34 * @OneToMany(targetEntity="ECommerceCategory", mappedBy="parent", cascade={"persist"})
39 * @ManyToOne(targetEntity="ECommerceCategory", inversedBy="children")
40 * @JoinColumn(name="parent_id", referencedColumnName="id")
44 public function __construct()
46 $this->products = new ArrayCollection();
47 $this->children = new ArrayCollection();
50 public function getId()
55 public function getName()
60 public function setName($name)
65 public function addProduct(ECommerceProduct $product)
67 if (!$this->products->contains($product)) {
68 $this->products[] = $product;
69 $product->addCategory($this);
73 public function removeProduct(ECommerceProduct $product)
75 $removed = $this->products->removeElement($product);
77 $product->removeCategory($this);
81 public function getProducts()
83 return $this->products;
86 private function setParent(ECommerceCategory $parent)
88 $this->parent = $parent;
91 public function getChildren()
93 return $this->children;
96 public function getParent()
101 public function addChild(ECommerceCategory $child)
103 $this->children[] = $child;
104 $child->setParent($this);
107 /** does not set the owning side. */
108 public function brokenAddChild(ECommerceCategory $child)
110 $this->children[] = $child;
114 public function removeChild(ECommerceCategory $child)
116 $removed = $this->children->removeElement($child);
118 $child->removeParent();
122 private function removeParent()
124 $this->parent = null;