Answer the question
In order to leave comments, you need to log in
Why is join column in Doctrine assigned to null before flush?
There are two entities
/**
* @Entity
* @Table(name="`order`")
*/
class Order
{
public function __construct()
{
$this->products = new ArrayCollection();
$this->totals = new ArrayCollection();
}
/**
* @Id
* @Column(type="integer")
*/
protected $order_id;
/**
* @Id
* @Column(type="integer")
*/
protected $order_code;
/**
* @Column(type="integer")
*/
protected $warehouse_id;
/**
* @OneToOne(targetEntity="\Core\Entities\Delivery\BoxberryTtn", mappedBy="ttn_boxberry", cascade={"persist", "remove"})
* @JoinColumn(name="order_code", referencedColumnName="order_code")
*/
protected $boxberry_ttn;
}
/**
* @Entity
* @Table(name="`ttn_boxberry`")
*/
class BoxberryTtn
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @Column(type="string")
*/
protected $ttn_num;
/**
* @Column(type="float", scale=2)
*/
protected $delivery_cost;
/**
* @Column(type="string")
*/
protected $order_code;
}
Answer the question
In order to leave comments, you need to log in
https://www.doctrine-project.org/projects/doctrine...
/**
* @OneToOne(targetEntity="\Core\Entities\Delivery\BoxberryTtn", mappedBy="ttn_boxberry", cascade={"persist", "remove"})
* @JoinColumn(name="order_code", referencedColumnName="id")
*/
protected $boxberry_ttn;
/**
* @Entity
* @Table(name="`ttn_boxberry`")
*/
class BoxberryTtn
{
/**
* @Id
* @Column(type="string")
* @GeneratedValue(strategy="NONE")
*/
protected $id;
public function __construct(string $id)
{
$this->id = $tid;
}
}
order_code
/**
* @Entity
* @Table(name="`order`")
*/
class Order
{
/**
* @Id
* @Column(type="integer")
*/
protected $order_code;
/**
* @OneToOne(targetEntity="\Core\Entities\Delivery\BoxberryTtn", mappedBy="ttn_boxberry", cascade={"persist", "remove"})
* @JoinColumn(name="order_code", referencedColumnName="order_code")
*/
protected $boxberry_ttn;
}
/**
* @Entity
* @Table(name="`order`")
*/
class Order
{
/**
* @Id
* @Column(type="integer")
*/
protected $order_id;
/**
* @Id
* @Column(type="integer")
*/
protected $order_code;
/**
* @Column(type="integer")
*/
protected $warehouse_id;
/**
* @OneToOne(targetEntity="\Core\Entities\Delivery\BoxberryTtn", cascade={"persist", "remove"})
* @JoinColumn(referencedColumnName="order_code")
*/
protected $boxberry_ttn;
public function __construct(int $order_id, string $order_code)
{
$this->order_id = $order_id;
$this->order_code = $order_code;
}
}
/**
* @Entity
* @Table(name="`ttn_boxberry`")
*/
class BoxberryTtn
{
/**
* @Id
* @Column(type="string")
* @GeneratedValue(strategy="NONE")
*/
protected $order_code;
/**
* @Column(type="string")
*/
protected $ttn_num;
/**
* @Column(type="float", scale=2)
*/
protected $delivery_cost;
public function __construct(Order $order)
{
$this->order_code = $order->getOrderCode();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question