Optional one-to-one relationship is not respected in Outletmapper::update()

11 views
Skip to first unread message

Holtkamp

unread,
Oct 17, 2010, 4:16:16 PM10/17/10
to Outlet ORM
I have defined an Order class, which has an optional one-to-one
relation with an Invoice class. If the order has not been confirmed
yet, no Invoice will be created, that is why the relationship is
optional.

However, for an already saved Order without an Invoice attached, when
I create a new Invoice, add it to the Order, and try to update the
Order, the reference to the newly created Invoice (in the database the
column orders.invoiceId), is not stored.

It seems that in the OutletMapper::update() method, the '$this-
>saveOneToOne( $obj, $entityCfg );' part is missing, is this correct?

OutletMapper.php:
public function update(&$obj, OutletEntityConfig $entityCfg) {
//Added, as during an update a relation might be added that was not
there at the moment of the INSERT
$this->saveOneToOne( $obj, $entityCfg );
// this first since this references the key
$this->saveManyToOne($obj, $entityCfg);
$this->saveOneToOne( $obj, $entityCfg );
.....
}

After adding it, the following code works as expected:
//When the Order has no Invoice, create it, add it to Order and update
the Order
if(!$order->hasInvoice()){
//Assign the invoice to the order
$invoice = new Invoice();
$invoice->setOrder($order);
$order->setInvoice($invoice);

$dao = new Dao_Outlet_Order();
$order = $dao->save($order);
}


Cheers!
Reply all
Reply to author
Forward
0 new messages