mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-09-21 18:25:02 -04:00
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:
1 parent
a7f1994404
commit
ddf8d5df96
1 file changed
+4
-2
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user