添加联接关系后不保存列的原则


Doctrine not saving column after join relationship was added

我正在使用条令,并向实体添加了一个联接。在联接之后,当setter(setcustomerorderID)的数据保存到数据库时,它们将不再被保存。每隔一列都会被保存。联接是正确的,并且设置了$this->data->orderId。

代码在没有联接的情况下工作。

我添加了如下关系:

/**
 * @var orders
 *
 * @ORM'ManyToOne(targetEntity="FYP'CartBundle'Entity'Orders", inversedBy="CustomerDesign")
 * @ORM'JoinColumn(name="customerorder_id", referencedColumnName="orderID")
 */
private $orders;

反面:

/**
 * @var customerDesign
 *
 * @ORM'OneToMany(targetEntity="FYP'BaseDesignBundle'Entity'CustomerDesign", mappedBy="orders")
 */
private $customerDesign;

正在尝试在其他文件中设置customerorder_id。

 $cd = new CustomerDesign();
 $cd->setcustomerID($this->data->customerId);
 $cd->setcustomerorderID($this->data->orderId); 
 $cd->setQuantity($cartItem->getQuantity());
 $cd->setProductVariant($cartItem->getProductVariant());
 $cd->setDesignData($cartItem->getDesignData());
 $cd->setRequestProof($cartItem->getRequestProof());
 $cd->setComments($cartItem->getComments());
 $cd->setSpecialComments($cartItem->getSpecialComments());
 $cd->setgiftSetID($cartItem->getgiftSetID());
 $cd->setgiftSetParent($cartItem->getgiftSetParent());
 $cd->setisBlank($cartItem->getisBlank());
 $cd->setbasedOn($cartItem->getbasedOn());
 $cd->setApprovalData($cartItem->getApprovalData());
 $cd->setdesignName('');
 $this->em->persist($cd);
 $this->em->flush();

此$cd->setcustomerorderID($This->data->orderId);根本不起作用。

setcustomerorderID看起来像:

    /**
 * Set customerorder_id
 *
 * @param integer $customerorder_id
 */
public function setcustomerorderID($customerorder_id)
{
    $this->customerorder_id = $customerorder_id;
}

谢谢。

在此处更改代码:

/**
 * @var order
 *
 * @ORM'ManyToOne(targetEntity="FYP'CartBundle'Entity'Orders", inversedBy="CustomerDesign")
 * @ORM'JoinColumn(name="customerorder_id", referencedColumnName="orderID")
 */
private $order;

据我所知,根据你们的关系,你们可能有一个订单对多个客户的设计。

您需要分配实体,而不是ID。

详细信息可在条令文件中找到。

<?php
$order = new Order();
$design = new CustomerDesign();
$design->setOrder($order);
...

public function setOrder($order)
{
    $this->order = $order;
}
...
$this->em->persist($order);
$this->em->persist($design);
$this->em->flush();

您创建了关系,这意味着customerorder_id处于ORM控制之下。