Version: 3.2.6
Bug Description
When updating a related row using an external repository/model ($this->order_product->find(...)->update(...)), a subsequent call to $parent->related('...')->fetchAll() returns stale (pre-update) data.
However, if I call $relatedRow->update(...) directly on the row from related(), the update is reflected correctly.
Steps To Reproduce
$order = $this->order_db->find($id);
if ($order) {
$opPrice = [];
foreach ($order->related('order_product')->fetchAll() as $op) {
$opPrice[$op->id]['original'] = $op->price;
//$op->update(['price' => rand(0, 100)]); // works
$product = $this->order_product->find($op->id);
$opPrice[$op->id]['new'] = rand(0,100);
$product->update(["price" => $opPrice[$op->id]['new']]);
}
foreach ($order->related('order_product')->fetchAll() as $op) {
$opPrice[$op->id]['wrong'] = $op->price; // still old
$opPrice[$op->id]['actual'] = $this->order_product->find($op->id)->offsetGet('price'); // correct
}
dump($opPrice);
}
Important detail
This code works
foreach ($order->related('order_product')->fetchAll() as $op) {
$op->update(['price' => rand(0, 100)]); // then fetchAll() will reflect the change
}
Database schema
• order: id
• order_product: id, order_id, product_id, price
Notes
Looks like internal caching of the related(...) result is not cleared or invalidated when updates happen via external fetches.
Version: 3.2.6
Bug Description
When updating a related row using an external repository/model (
$this->order_product->find(...)->update(...)), a subsequent call to$parent->related('...')->fetchAll()returns stale (pre-update) data.However, if I call
$relatedRow->update(...)directly on the row fromrelated(), the update is reflected correctly.Steps To Reproduce
Important detail
This code works
Database schema
Notes
Looks like internal caching of the related(...) result is not cleared or invalidated when updates happen via external fetches.