Vote count:
0
I have a weird problem whereby one of my relations in my models is updating the foreign key to the wrong figure.
I have classes Order, OrderProduct and OrderAddresses. The following:
$order_addresses = OrderAddress::find(array(
"conditions" => "order_id = :order_id: and active = 'Y'",
"bind" => array("order_id" => $order->getId())
));
foreach ( $order_addresses as $order_address ) {
$order_address->save();
}
For whatever reason, before I run the code above, my foreign keys in the database are all correct, however when that code is run, the following SQL happens which sets the foreign key (order_id) to the number of a model that was used in the code previously:
UPDATE `order_address` SET `order_id` = ?, `address_id` = ? WHERE `id` = ?
I have no idea what is going on here and can't find a workaround.
OrderAddress
public function initialize()
{
//use softdelete
$this->addBehavior(new SoftDelete(
array(
"field" => "active",
"value" => "N"
)
));
parent::initialize();
$this->belongsTo("order_id", "Order", "id", array(
"alias" => "order"
));
$this->belongsTo("address_id", "Address", "id", array(
"alias" => "address"
));
}
Order
$this->hasMany("id", "OrderAddress", "order_id", array( "alias" => "addresses" ));
asked 20 secs ago
Phalcon is updating my foreign key to incorrect value
Aucun commentaire:
Enregistrer un commentaire