mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 11:18:51 +02:00
Delete ProjectBOMEntry when the associated part is deleted
This commit is contained in:
parent
fb91d98d13
commit
5521995f79
2 changed files with 46 additions and 35 deletions
|
@ -25,6 +25,7 @@ namespace App\Entity\Parts;
|
||||||
use App\Entity\Attachments\Attachment;
|
use App\Entity\Attachments\Attachment;
|
||||||
use App\Entity\Attachments\AttachmentContainingDBElement;
|
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||||
use App\Entity\Attachments\PartAttachment;
|
use App\Entity\Attachments\PartAttachment;
|
||||||
|
use App\Entity\Parts\PartTraits\ProjectTrait;
|
||||||
use App\Entity\ProjectSystem\Project;
|
use App\Entity\ProjectSystem\Project;
|
||||||
use App\Entity\Parameters\ParametersTrait;
|
use App\Entity\Parameters\ParametersTrait;
|
||||||
use App\Entity\Parameters\PartParameter;
|
use App\Entity\Parameters\PartParameter;
|
||||||
|
@ -64,12 +65,7 @@ class Part extends AttachmentContainingDBElement
|
||||||
use ManufacturerTrait;
|
use ManufacturerTrait;
|
||||||
use OrderTrait;
|
use OrderTrait;
|
||||||
use ParametersTrait;
|
use ParametersTrait;
|
||||||
|
use ProjectTrait;
|
||||||
/**
|
|
||||||
* @var Collection<int, ProjectBOMEntry> $project_bom_entries
|
|
||||||
* @ORM\OneToMany(targetEntity="App\Entity\ProjectSystem\ProjectBOMEntry", mappedBy="part")
|
|
||||||
*/
|
|
||||||
protected $project_bom_entries = [];
|
|
||||||
|
|
||||||
/** @var Collection<int, PartParameter>
|
/** @var Collection<int, PartParameter>
|
||||||
* @Assert\Valid()
|
* @Assert\Valid()
|
||||||
|
@ -151,33 +147,4 @@ class Part extends AttachmentContainingDBElement
|
||||||
}
|
}
|
||||||
parent::__clone();
|
parent::__clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all ProjectBOMEntries that use this part.
|
|
||||||
* @return Collection<int, ProjectBOMEntry>|ProjectBOMEntry[]
|
|
||||||
*/
|
|
||||||
public function getProjectBomEntries(): Collection
|
|
||||||
{
|
|
||||||
return $this->project_bom_entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all devices which uses this part.
|
|
||||||
*
|
|
||||||
* @return Project[] * all devices which uses this part as a one-dimensional array of Device objects
|
|
||||||
* (empty array if there are no ones)
|
|
||||||
* * the array is sorted by the devices names
|
|
||||||
*/
|
|
||||||
public function getProjects(): array
|
|
||||||
{
|
|
||||||
$projects = [];
|
|
||||||
|
|
||||||
foreach($this->project_bom_entries as $entry) {
|
|
||||||
$projects[] = $entry->getProject();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $projects;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
44
src/Entity/Parts/PartTraits/ProjectTrait.php
Normal file
44
src/Entity/Parts/PartTraits/ProjectTrait.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity\Parts\PartTraits;
|
||||||
|
|
||||||
|
use App\Entity\ProjectSystem\Project;
|
||||||
|
use App\Entity\ProjectSystem\ProjectBOMEntry;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
trait ProjectTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Collection<int, ProjectBOMEntry> $project_bom_entries
|
||||||
|
* @ORM\OneToMany(targetEntity="App\Entity\ProjectSystem\ProjectBOMEntry", mappedBy="part", cascade={"remove"}, orphanRemoval=true)
|
||||||
|
*/
|
||||||
|
protected $project_bom_entries = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all ProjectBOMEntries that use this part.
|
||||||
|
* @return Collection<int, ProjectBOMEntry>|ProjectBOMEntry[]
|
||||||
|
*/
|
||||||
|
public function getProjectBomEntries(): Collection
|
||||||
|
{
|
||||||
|
return $this->project_bom_entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all devices which uses this part.
|
||||||
|
*
|
||||||
|
* @return Project[] * all devices which uses this part as a one-dimensional array of Device objects
|
||||||
|
* (empty array if there are no ones)
|
||||||
|
* * the array is sorted by the devices names
|
||||||
|
*/
|
||||||
|
public function getProjects(): array
|
||||||
|
{
|
||||||
|
$projects = [];
|
||||||
|
|
||||||
|
foreach($this->project_bom_entries as $entry) {
|
||||||
|
$projects[] = $entry->getProject();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $projects;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue