mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Added some constraints to ensure validity of the PartAssociation entities
This commit is contained in:
parent
c7892cb9e2
commit
cc2332a83a
2 changed files with 24 additions and 0 deletions
|
@ -28,6 +28,7 @@ use Doctrine\DBAL\Types\Types;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
|
@ -36,6 +37,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
*/
|
||||
#[ORM\Entity(repositoryClass: DBElementRepository::class)]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
#[UniqueEntity(fields: ['other', 'owner', 'type'], message: 'validator.part_association.already_exists')]
|
||||
class PartAssociation extends AbstractDBElement
|
||||
{
|
||||
use TimestampTrait;
|
||||
|
@ -51,6 +53,8 @@ class PartAssociation extends AbstractDBElement
|
|||
* is used if the type is OTHER
|
||||
*/
|
||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
||||
#[Assert\Expression("this.getType().value !== 0 or this.getOtherType() !== null",
|
||||
message: 'validator.part_association.must_set_an_value_if_type_is_other')]
|
||||
protected ?string $other_type = null;
|
||||
|
||||
/**
|
||||
|
@ -73,6 +77,8 @@ class PartAssociation extends AbstractDBElement
|
|||
#[ORM\ManyToOne(targetEntity: Part::class, inversedBy: 'associated_parts_as_other')]
|
||||
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||
#[Assert\NotNull]
|
||||
#[Assert\Expression("this.getOwner() !== this.getOther()",
|
||||
message: 'validator.part_association.part_cannot_be_associated_with_itself')]
|
||||
protected ?Part $other = null;
|
||||
|
||||
public function getType(): AssociationType
|
||||
|
|
|
@ -317,5 +317,23 @@
|
|||
<target>A lot owner must not be the anonymous user!</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="N8aA0Uh" name="validator.part_association.must_set_an_value_if_type_is_other">
|
||||
<segment>
|
||||
<source>validator.part_association.must_set_an_value_if_type_is_other</source>
|
||||
<target>If you set the type to "other", then you have to set a descriptive value for it!</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="9VYNZ4v" name="validator.part_association.part_cannot_be_associated_with_itself">
|
||||
<segment>
|
||||
<source>validator.part_association.part_cannot_be_associated_with_itself</source>
|
||||
<target>A part can not be associated with itself!</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="csc1PNn" name="validator.part_association.already_exists">
|
||||
<segment>
|
||||
<source>validator.part_association.already_exists</source>
|
||||
<target>The association with this part already exists!</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue