mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
model类saveall方法自动识别数据
This commit is contained in:
@@ -729,17 +729,22 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* 保存多个数据到当前数据对象
|
* 保存多个数据到当前数据对象
|
||||||
* @access public
|
* @access public
|
||||||
* @param array $dataSet 数据
|
* @param array $dataSet 数据
|
||||||
|
* @param boolean $replace 是否自动识别更新和写入
|
||||||
* @return array|false
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
public function saveAll($dataSet)
|
public function saveAll($dataSet, $replace = true)
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
$db->startTrans();
|
$db->startTrans();
|
||||||
try {
|
try {
|
||||||
foreach ($dataSet as $key => $data) {
|
foreach ($dataSet as $key => $data) {
|
||||||
|
if ($replace && isset($data[$this->getPk()])) {
|
||||||
|
$result[$key] = self::update($data);
|
||||||
|
} else {
|
||||||
$result[$key] = self::create($data);
|
$result[$key] = self::create($data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$db->commit();
|
$db->commit();
|
||||||
return $result;
|
return $result;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user