我有两个实体,ParkingType和Exception,它们之间存在一个OneToMany关系,因为每个ParkingType可以具有多个异常。
我做到了,所以每当我创建一个新的ParkingType时,我也可以同时创建与其相关的异常。我通过使用一个包含在parkingtype表单内的异常表单的CollectionType做到了这一点。集合类型是动态的,因此我可以根据需要添加尽可能多的异常。
问题:异常表中有一列名为type_id的列,该列用于将该异常与ParkingType相关联,我每次必须通过从下拉列表中进行选择来自己填充该字段。我不想这样做,我希望该字段引用默认情况下刚创建的对象。我的代码:异常实体:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\ExceptionRepository")
*/
class Exception
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=200, nullable=true)
*/
private $nom;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $datedebut;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $datefin;
/**
* @ORM\Column(type="time", nullable=true)
*/
private $tempsdebut;
/**
* @ORM\Column(type="time", nullable=true)
*/
private $tempsfin;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\TypeParking", inversedBy="exceptions")
* @ORM\JoinColumn(nullable=false)
*/
private $type;
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(?string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getDatedebut(): ?\DateTimeInterface
{
return $this->datedebut;
}
public function setDatedebut(?\DateTimeInterface $datedebut): self
{
$this->datedebut = $datedebut;
return $this;
}
public function getDatefin(): ?\DateTimeInterface
{
return $this->datefin;
}
public function setDatefin(?\DateTimeInterface $datefin): self
{
$this->datefin = $datefin;
return $this;
}
public function getTempsdebut(): ?\DateTimeInterface
{
return $this->tempsdebut;
}
qq_花开花谢_0