Hi I have many, many relationships between Items (Products) and categories, and I implemented these three objects:
Object Object:
use Doctrine\Common\Collections\ArrayCollection; class Item { private $id_item; protected $categories; public function __construct() { $this->categories=new ArrayCollection(); } public function addCategory(ItemCategories $category){ $this->categories->add($category); } public function getCategories(){ return $this->categories; } }
2 Attach a table (ItemCategories)
class ItemCategories { private $id; private $id_item; private $id_category; protected $category; protected $item; public function getCategory() { return $this->category; } public function setCategory($category) { $this->category = $category; } public function getItem() { return $this->item; } public function setItem($item) { $this->item = $item; } }
Table 3.Categories
class Category { private $id_category; protected $ItemCategories; }
Now my problem is that I do not know how to insert an element using EXISTING categories. I tried:
$item= new Entity\Item(); $itemCategoriesReferences=new Entity\ItemCategories(); $productCategoriesReferences->setItem($product);
I know this doesn't really matter, but I have no other idea, so please help me.
thanks
source share