0

I'm using doctrine and I added a join to an entity. After the join a setter (setcustomerorderID) is no longer being saved when they data is saved to the database. Every other column gets saved. The join is correct and $this->data->orderId is set.

The code works without the join.

I added the relationship as follows:

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

On the reverse side:

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

Attempting to set customerorder_id in a different file.

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

This $cd->setcustomerorderID($this->data->orderId); is not working at all.

setcustomerorderID Looks like:

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

Thanks.

1 Answer 1

0

Change your code here:

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

As far as I understand, according your relationships, you might have one order to many customer designs.

Instead of ID, you need to assign Entity.

Details can be found in Doctrine documentation.

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

You created relationships, and it means customerorder_id is under ORM control.

4
  • Thats what I thought the problem was but when I add that I get a 500 error.
    – Jeremy
    Mar 25, 2016 at 20:18
  • I wrote another example depends on your current relationships
    – snsanich
    Mar 25, 2016 at 20:23
  • Ok I got it working without error, but it's still setting the row in the table to null instead of the id.
    – Jeremy
    Mar 25, 2016 at 20:33
  • For new objects we need to call persist for both main object and related objects.
    – snsanich
    Mar 25, 2016 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.