Make categories and project categories be related many-to-many in db

This commit is contained in:
2025-10-01 15:38:50 +02:00
parent 617196c66b
commit 423f0efcc6
5 changed files with 169 additions and 9 deletions
+23 -6
View File
@@ -3,6 +3,7 @@
namespace App\Entity\Project;
use App\Entity\Accounting\Accounting;
use App\Entity\Category;
use App\Entity\Interface\AccountingOwnerInterface;
use App\Entity\Interface\LocalizedEntityInterface;
use App\Entity\Interface\UserOwnedInterface;
@@ -64,8 +65,11 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized
#[ORM\Embedded(class: ProjectCalendar::class)]
private ?ProjectCalendar $calendar = null;
#[ORM\Column(enumType: ProjectCategory::class)]
private ?ProjectCategory $category = null;
/**
* @var Collection<int, Category>
*/
#[ORM\ManyToMany(targetEntity: Category::class)]
private Collection $categories;
/**
* Project's territory of interest.
@@ -145,6 +149,7 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized
$this->budgetItems = new ArrayCollection();
$this->updates = new ArrayCollection();
$this->supports = new ArrayCollection();
$this->categories = new ArrayCollection();
}
public function getId(): ?int
@@ -219,14 +224,26 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized
return $this;
}
public function getCategory(): ?ProjectCategory
/**
* @return Collection<int, Category>
*/
public function getCategories(): Collection
{
return $this->category;
return $this->categories;
}
public function setCategory(ProjectCategory $category): static
public function addCategory(Category $category): static
{
$this->category = $category;
if (!$this->categories->contains($category)) {
$this->categories->add($category);
}
return $this;
}
public function removeCategory(Category $category): static
{
$this->categories->removeElement($category);
return $this;
}