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



我必须保存一个包含ticket_attachmentsticket_commentsticket_status_historyticket。 我将只保留ticket对象,但想保存附件,评论和历史记录。我正在使用教义、符号和注释。

我在ticket中使用 mappedBy 和级联删除并持久化创建了 3 个数组集合。并在附件、评论和历史记录中使用反转。但是在持久化和刷新后,仅保存ticket,但其他对象(即附件,注释和历史记录(未保存。但显示没有错误

票.php

/**
* @ORMOneToMany(targetEntity="AppBundleEntityTicketAttachments", mappedBy="ticket", cascade={"persist", "remove"})
*/
private $attachments;
/**
* @ORMOneToMany(targetEntity="AppBundleEntityTicketComments", mappedBy="ticket", cascade={"persist", "remove"})
*/
private $comments;
/**
* @ORMOneToMany(targetEntity="AppBundleEntityTicketStatusHistory", mappedBy="ticket", cascade={"persist", "remove"})
*/
private $historys;
public function __construct()
{
$this->attachments = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->historys = new ArrayCollection();
}

历史记录、评论和附件.php

/**
* @var AppBundleEntityTicket
*
* @ORMManyToOne(targetEntity="AppBundleEntityTicket", inversedBy="historys")
* @ORMJoinColumns({
*   @ORMJoinColumn(name="ticket_id", referencedColumnName="id")
* })
*/
private $ticket;

都有它的二传手和吸盘手。问题出在哪里?

你把它们设置为彼此吗?如:

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

它们必须在二传器中相互关联(或其他方式(,才能级联持久工作。

最新更新