我正在尝试使用symfony框架来制作这个小项目,这很简单,但是我仍然很陌生。我有3个实体,即Classe,Student和WorkDays。班级与学生有一个OneToMany关系,而与日程表有另一个OneToMany关系。创建课程时,您可以在这里添加学生和WorkDay,这是我的代码:Classe实体:
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\ClasseRepository")
*/
class Classe
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=200)
*/
private $label;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Student", mappedBy="classe", orphanRemoval=true)
*/
private $Students;
/**
* @ORM\OneToMany(targetEntity="App\Entity\WorkDays", mappedBy="class")
*/
private $schedule;
public function __construct()
{
$this->Students = new ArrayCollection();
$this->schedule = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
/**
* @return Collection|Student[]
*/
public function getStudents(): Collection
{
return $this->Students;
}
public function addStudent(Student $student): self
{
if (!$this->Students->contains($student)) {
$this->Students[] = $student;
$student->setClasse($this);
}
return $this;
}
public function removeStudent(Student $student): self
{
if ($this->Students->contains($student)) {
$this->Students->removeElement($student);
// set the owning side to null (unless already changed)
if ($student->getClasse() === $this) {
$student->setClasse(null);
}
}
return $this;
}
我的问题: 有什么办法可以避免重复学生姓名和工作日姓名?与班级名称相同吗?
qq_花开花谢_0