chill-bundles/src/Bundle/ChillDocStoreBundle/Entity/AccompanyingCourseDocument.php
Julien Fastré 4be6c09d4d
Add unique constraints to prevent person_documnt and accompanyingcourse_document with duplicated object_id
This change ensures `object_id` uniqueness within `person_document` and `accompanyingcourse_document` tables. It includes migration scripts and entity annotations to enforce these constraints. This helps maintain data integrity and consistency across the database.
2024-11-19 10:50:46 +01:00

64 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocStoreBundle\Entity;
use Chill\MainBundle\Entity\HasCentersInterface;
use Chill\MainBundle\Entity\HasScopesInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table('chill_doc.accompanyingcourse_document')]
#[ORM\UniqueConstraint(name: 'acc_course_document_unique_stored_object', columns: ['object_id'])]
class AccompanyingCourseDocument extends Document implements HasScopesInterface, HasCentersInterface
{
#[ORM\ManyToOne(targetEntity: AccompanyingPeriod::class)]
#[ORM\JoinColumn(nullable: false)]
private ?AccompanyingPeriod $course = null;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)]
private ?int $id = null;
public function getCenters(): ?iterable
{
return $this->course->getCenters();
}
public function getCourse(): ?AccompanyingPeriod
{
return $this->course;
}
public function getId()
{
return $this->id;
}
public function getScopes(): iterable
{
if (null === $this->course) {
return [];
}
return $this->course->getScopes();
}
public function setCourse(?AccompanyingPeriod $course): self
{
$this->course = $course;
return $this;
}
}