Hi,
I was wondering what the best strategy is for updating all references to an Object.
Example (sequence of code)
(a) class 1: retrieves $order
(b) class 2: retrieves same $order (same ID) and changes value of $order->MyRelationshipID, followed by $order->write();
.... and maybe ....
(b2) class 3: retrieves same $order (same ID) and changes value of $order->MyRelationshipID, followed by $order->write();
....
(c) class 1: checks $order->MyRelationshipID value
which is now out of date.
What do you recommend in terms of avoiding this situation where you can not always control that both class 1 and class 2 use the exact same object reference (e.g. by the use of DataObject::get_one or a similar type of caching technique).
I dont fully understand why or how this works yet.... but what seems to solve is to re-retrieve object from database:
$oder->MyRelationshipID is "OUTDATED"
$order = Order::get()->filter(['ID' => $order->ID])->first();
$oder->MyRelationshipID is "CORRECT"
It may perhaps relate to this issue: