0

我有两个班级:年级和假期。

一个等级可以包含零个、一个或多个假期。

所以我有一个看起来像这样的表格:

在此处输入图像描述

我可以使用一些 Javascript 添加或删除假期。

问题出在我的控制器上,当我收到请求时,上面只有最后一个假期(图中的“2nd”,没有收到“1st”)。

在此处输入图像描述

有人知道为什么他们没有全部发送吗?

我的课程 :

-年级 :

class Grade {

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=50)
 * @Assert\NotBlank
 */
protected $name;

/**
 * @Gedmo\Slug(fields={"name"}, updatable=false)
 * @ORM\Column(length=50, unique=true)
 */
protected $slug;

/**
* @ORM\ManyToOne(targetEntity="Ent\HomeBundle\Entity\Campus", inversedBy="grades")
* @ORM\JoinColumn(onDelete="CASCADE")
* @Assert\NotBlank
* @Exclude
**/
protected $campus;

/**
* @ORM\OneToMany(targetEntity="\Ent\TimeBundle\Entity\Course", mappedBy="grade")
* @Assert\NotBlank
* @Exclude
**/
protected $courses;

/**
* @ORM\ManyToOne(targetEntity="\Ent\HomeBundle\Entity\School", inversedBy="grades")
* @Assert\NotBlank
* @Exclude
**/
protected $school;

/**
* @ORM\OneToMany(targetEntity="\Ent\TimeBundle\Entity\Alert", mappedBy="grade")
* @Exclude
**/
protected $alerts;

/**
 * @ORM\ManyToMany(targetEntity="\Ent\TimeBundle\Entity\Holiday", inversedBy="grades", cascade={"persist"})
 * @ORM\JoinTable(name="grade_holiday",
 *  joinColumns={@ORM\JoinColumn(name="grade_id", referencedColumnName="id")},
 *  inverseJoinColumns={@ORM\JoinColumn(name="holiday_id", referencedColumnName="id")}
 * )
 */
protected $holidays;

public function __toString() {
    return $this->name;
}

public function __construct() {
    $this->courses = new \Doctrine\Common\Collections\ArrayCollection();
    $this->alerts = new \Doctrine\Common\Collections\ArrayCollection();
    $this->holidays = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
 * Get id
 *
 * @return integer
 */
public function getId() {
    return $this->id;
}

/**
 * Set name
 *
 * @param string $name
 * @return Grade
 */
public function setName($name) {
    $this->name = $name;

    return $this;
}

/**
 * Get name
 *
 * @return string
 */
public function getName() {
    return $this->name;
}

/**
 * Set slug
 *
 * @param string $slug
 * @return Grade
 */
public function setSlug($slug) {
    $this->slug = $slug;

    return $this;
}

/**
 * Get slug
 *
 * @return string
 */
public function getSlug() {
    return $this->slug;
}

/**
 * Set campus
 *
 * @param \Ent\HomeBundle\Entity\Campus $campus
 * @return Grade
 */
public function setCampus(\Ent\HomeBundle\Entity\Campus $campus = null) {
    $this->campus = $campus;

    return $this;
}

/**
 * Get campus
 *
 * @return \Ent\HomeBundle\Entity\Campus
 */
public function getCampus() {
    return $this->campus;
}

/**
 * Add courses
 *
 * @param \Ent\TimeBundle\Entity\Course $courses
 * @return Grade
 */
public function addCourse(\Ent\TimeBundle\Entity\Course $courses) {
    $this->courses[] = $courses;

    return $this;
}

/**
 * Remove courses
 *
 * @param \Ent\TimeBundle\Entity\Course $courses
 */
public function removeCourse(\Ent\TimeBundle\Entity\Course $courses) {
    $this->courses->removeElement($courses);
}

/**
 * Get courses
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getCourses() {
    return $this->courses;
}

/**
 * Set school
 *
 * @param \Ent\HomeBundle\Entity\School $school
 * @return Grade
 */
public function setSchool(\Ent\HomeBundle\Entity\School $school = null) {
    $this->school = $school;

    return $this;
}

/**
 * Get school
 *
 * @return \Ent\HomeBundle\Entity\School
 */
public function getSchool() {
    return $this->school;
}

/**
 * Add alerts
 *
 * @param \Ent\TimeBundle\Entity\Alert $alerts
 * @return Grade
 */
public function addAlert(\Ent\TimeBundle\Entity\Alert $alerts) {
    $this->alerts[] = $alerts;

    return $this;
}

/**
 * Remove alerts
 *
 * @param \Ent\TimeBundle\Entity\Alert $alerts
 */
public function removeAlert(\Ent\TimeBundle\Entity\Alert $alerts) {
    $this->alerts->removeElement($alerts);
}

/**
 * Get alerts
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getAlerts() {
    return $this->alerts;
}

/**
 * Add holiday
 *
 * @param \Ent\TimeBundle\Entity\Holiday $holiday
 * @return Grade
 */
public function addHoliday(\Ent\TimeBundle\Entity\Holiday $holiday) {
    $this->holidays[] = $holiday;

    return $this;
}

/**
 * Remove holidays
 *
 * @param \Ent\TimeBundle\Entity\Holiday $holidays
 */
public function removeHoliday(\Ent\TimeBundle\Entity\Holiday $holidays) {
    $this->holidays->removeElement($holidays);
}

/**
 * Get holidays
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getHolidays()
{
    return $this->holidays;
}

/**
 * Set holidays
 *
 * @param \Doctrine\Common\Collections\ArrayCollection $holidays
 * @return Grade
 */
public function setHolidays(\Doctrine\Common\Collections\ArrayCollection $holidays) {

    $this->holidays = $holidays;

    return $this;
}

}

-假期

class Holiday {

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=50, unique=true)
 * @Assert\NotBlank
 */
protected $name;

/**
 * @Gedmo\Slug(fields={"name"}, updatable=false)
 * @ORM\Column(length=50, unique=true)
 */
protected $slug;

/**
* @ORM\ManyToMany(targetEntity="\Ent\UserBundle\Entity\Grade", mappedBy="holidays", cascade={"persist"})
**/
protected $grades;

/**
* @ORM\Column(type="date")
* @Assert\NotBlank
**/
protected $begin;

/**
* @ORM\Column(type="date", nullable=true)
**/
protected $end;

public function __construct() {
    $this->grades = new \Doctrine\Common\Collections\ArrayCollection();
}

public function __toString() {
    return $this->name;
}

/**
 * Get id
 *
 * @return integer
 */
public function getId() {
    return $this->id;
}

/**
 * Set begin
 *
 * @param \DateTime $begin
 * @return Holiday
 */
public function setBegin($begin) {
    $this->begin = $begin;

    return $this;
}

/**
 * Get begin
 *
 * @return \DateTime
 */
public function getBegin() {
    return $this->begin;
}

/**
 * Set end
 *
 * @param \DateTime $end
 * @return Holiday
 */
public function setEnd($end) {
    $this->end = $end;

    return $this;
}

/**
 * Get end
 *
 * @return \DateTime
 */
public function getEnd() {
    return $this->end;
}

/**
 * Set name
 *
 * @param string $name
 * @return Holiday
 */
public function setName($name) {
    $this->name = $name;

    return $this;
}

/**
 * Get name
 *
 * @return string
 */
public function getName() {
    return $this->name;
}

/**
 * Set slug
 *
 * @param string $slug
 * @return Holiday
 */
public function setSlug($slug) {
    $this->slug = $slug;

    return $this;
}

/**
 * Get slug
 *
 * @return string
 */
public function getSlug() {
    return $this->slug;
}

/**
 * Add grades
 *
 * @param \Ent\UserBundle\Entity\Grade $grades
 * @return Holiday
 */
public function addGrade(\Ent\UserBundle\Entity\Grade $grades) {
    $this->grades[] = $grades;

    return $this;
}

/**
 * Remove grades
 *
 * @param \Ent\UserBundle\Entity\Grade $grades
 */
public function removeGrade(\Ent\UserBundle\Entity\Grade $grades) {
    $this->grades->removeElement($grades);
}

/**
 * Get grades
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getGrades() {
    return $this->grades;
}

/**
* Set grades
*
* @param \Ent\UserBundle\Entity\Grade $grades
*/
public function setGrades(\Ent\UserBundle\Entity\Grade $grades) {

    $this->grades = $grades;
}
}
4

0 回答 0