mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
Model类saveall方法支持事务
This commit is contained in:
@@ -636,10 +636,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
public function saveAll($dataSet)
|
||||
{
|
||||
$result = 0;
|
||||
foreach ($dataSet as $data) {
|
||||
$result = $this->isUpdate(false)->save($data, [], false);
|
||||
$db = $this->db();
|
||||
$db->startTrans();
|
||||
try {
|
||||
foreach ($dataSet as $data) {
|
||||
$result = $this->isUpdate(false)->save($data, [], false);
|
||||
}
|
||||
$db->commit();
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
$db->rollback();
|
||||
return false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -248,7 +248,7 @@ class Merge extends Model
|
||||
}
|
||||
$db->commit();
|
||||
return $result;
|
||||
} catch (\PDOException $e) {
|
||||
} catch (\Exception $e) {
|
||||
$db->rollback();
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user