fix(models): use explicit SQL query to ensure atomic sort_order calculation

- Replaced query builder logic with an explicit SQL SELECT COUNT statement to calculate `sort_order` atomically within a transaction.

Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
This commit is contained in:
objecttothis committed 2026-08-19 17:45:39 +04:00
1 parent a7f1994404
commit ddf8d5df96
1 file changed
+4 -2
+4 -2
View File
@@ -260,10 +260,12 @@ class Stock_location extends Model
$locationDataToSave = ['location_name' => $locationName, 'deleted' => 0];
if (!$this->exists($locationId)) {
$table = $this->db->prefixTable('stock_locations');
$this->db->transStart();
$builder = $this->db->table('stock_locations');
$locationDataToSave['sort_order'] = $builder->where('deleted', 0)->countAllResults();
$row = $this->db->query("SELECT COUNT(*) AS count FROM $table WHERE deleted = 0 FOR UPDATE")->getRow();
$locationDataToSave['sort_order'] = (int) $row->count;
$builder = $this->db->table('stock_locations');
$builder->insert($locationDataToSave);