第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

自動在CollectionType中設(shè)置數(shù)據(jù)庫ID

自動在CollectionType中設(shè)置數(shù)據(jù)庫ID

PHP
ibeautiful 2021-05-03 14:15:33
我有兩個實體,ParkingType和Exception,它們之間存在一個OneToMany關(guān)系,因為每個ParkingType可以具有多個異常。我做到了,所以每當我創(chuàng)建一個新的ParkingType時,我也可以同時創(chuàng)建與其相關(guān)的異常。我通過使用一個包含在parkingtype表單內(nèi)的異常表單的CollectionType做到了這一點。集合類型是動態(tài)的,因此我可以根據(jù)需要添加盡可能多的異常。問題:異常表中有一列名為type_id的列,該列用于將該異常與ParkingType相關(guān)聯(lián),我每次必須通過從下拉列表中進行選擇來自己填充該字段。我不想這樣做,我希望該字段引用默認情況下剛創(chuàng)建的對象。我的代碼:異常實體:<?phpnamespace 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;    } 
查看完整描述

1 回答

?
qq_花開花謝_0

TA貢獻1835條經(jīng)驗 獲得超7個贊

只需從ExceptionType*中刪除字段,然后在中ParkingType,更改addException:


public function addException(Exception $exception)

{

    $this->exceptions->add($exception);

    $exception->setType($this); // <-- this is new.

}

更新:還必須將exceptionsCollectionType選項設(shè)置by_reference為false,這樣加法器實際上是由表單組件調(diào)用的。


這是做到這一點的一種方法。另一個選擇是在您的控制器中執(zhí)行此操作,并調(diào)用setType您在ParkingType中找到的每個Exception ...


*)這是假設(shè)您永遠不會自己編輯Exception。否則,可以有條件地在某些選項上添加停放類型表單字段,或者ParkingTypeExceptionType對不添加停放類型表單字段的“例外”(例如)使用其他表單。


查看完整回答
反對 回復 2021-05-07
  • 1 回答
  • 0 關(guān)注
  • 155 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號