简体   繁体   English

无法使用symfony和主义及其关联对象或表保存到postgresql中?

[英]Unable to save into postgresql using symfony and doctrine with its association objects or table?

I have to save a ticket with ticket_attachments , ticket_comments and ticket_status_history . 我要救一ticketticket_attachmentsticket_commentsticket_status_history I will persist only ticket object but want to save attachments,comments and history. 我将仅保留ticket对象,但要保存附件,评论和历史记录。 I am using doctrine and symfony and annotations. 我正在使用教义,symfony和注释。

I have created 3 array collections in ticket with mappedBy and cascade remove and persist. 我已经在带有cketedBy的ticket创建了3个数组集合,并级联删除并保留。 And used inversedBy in attachments, comments and history. 并在附件,评论和历史记录中使用了inversedBy。 But after persisting and flush only ticket is being saved but other objects ie attachments,comments and historys are not saving. 但是在持久保存和刷新后,仅保存了ticket ,但未保存其他对象,例如附件,注释和历史记录。 But shows No Error . 但是显示没有错误

Ticket.php Ticket.php

/**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\TicketAttachments", mappedBy="ticket", cascade={"persist", "remove"})
     */
    private $attachments;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\TicketComments", mappedBy="ticket", cascade={"persist", "remove"})
     */
    private $comments;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\TicketStatusHistory", mappedBy="ticket", cascade={"persist", "remove"})
     */
    private $historys;

    public function __construct()
    {
        $this->attachments = new ArrayCollection();
        $this->comments = new ArrayCollection();
        $this->historys = new ArrayCollection();
    }

History, Comments and Attachments.php 历史,评论和附件.php

/**
     * @var \AppBundle\Entity\Ticket
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Ticket", inversedBy="historys")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="ticket_id", referencedColumnName="id")
     * })
     */
    private $ticket;

All have it's setter and getter. 所有人都有它的二传手。 Where is the problem? 问题出在哪儿?

Are you setting them to each other? 您是否将它们彼此设置? As in: 如:

public function addToHistories($history) {
   $this->historys[] = $history;
   $history->setTicket($this);
}

They have to be associated with each other within the setters (or some other way) for cascade persist to work. 它们必须在设置器中彼此关联(或以其他方式),以使级联持续工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM