2017-08-14 104 views
1

我必须保存ticketticket_attachments,ticket_commentsticket_status_history。我只会坚持ticket对象,但想要保存附件,评论和历史记录。我正在使用教义和symfony和注释。无法使用symfony和doctrine及其关联对象或表保存到postgresql中?

我创建了3个数组集合ticket与mappedBy和级联删除并坚持。并通过附件,评论和历史反复使用。但在保存并刷新后,只有ticket正在保存,但其他对象(即附件,注释和历史记录)未保存。但显示没有错误

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(); 
    } 

历史,评论和Attachments.php

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

所有有它的setter和getter。哪里有问题?

+0

return $ this; (\ AppBundle \ Entity \ Ticket $ ticket = null) { $ this-> ticket = $ ticket;}附件中的公共函数setTicket(\ AppBundle \ Entity \ Ticket $ ticket = null) {this-> ticket = $ ticket; return $ this; }' – Hunter

回答

0

您是否将它们设置为彼此?如在:

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

它们必须在setter(或其他方式)内相互关联以便级联持续工作。在公共函数setTicketAttachmentsList($附件){ $ this-> attachments = $ attachments;}附件的Ticket.php中的

相关问题