I have an Item object which has a 1:n relation to categories. My Item Model contains:
setCategories(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories)
getCategories()
addCategory(VENDX\Items\Domain\Model\Category $category)
removeCategory(VENDX\Items\Domain\Model\Category $category)
but I am not able to add multiple categories to an itemobject. i tried:
$category = $this->objectManager->get('VENDX\Items\Domain\Model\Category');
$category->setCatName('Cat1'); //First category
$item->addCatgeory($category);
$category->setCatName('Cat2'); //Second category
$item->addCategory($category);
after adding $item to my $itemrepository it just saves the last category "Cat2" into the db. What am i missing??
also tried that:
$categories = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\ObjectStorage');
$category = $this->objectManager->get('VENDX\Items\Domain\Model\Category');
$category->setCatName('Cat1'); //First category
$categories->attach($category);
$category->setCatName('Cat2'); //Second category
$categories->attach($category);
$item->setCategories($categories);
same issue with the above code. It just saves the last (second) category. How can i add multiple categories to my item-object?