mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进saveall方法
This commit is contained in:
@@ -730,7 +730,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @access public
|
* @access public
|
||||||
* @param array $dataSet 数据
|
* @param array $dataSet 数据
|
||||||
* @param boolean $replace 是否自动识别更新和写入
|
* @param boolean $replace 是否自动识别更新和写入
|
||||||
* @return array|false
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function saveAll($dataSet, $replace = true)
|
public function saveAll($dataSet, $replace = true)
|
||||||
{
|
{
|
||||||
@@ -738,8 +738,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
$db->startTrans();
|
$db->startTrans();
|
||||||
try {
|
try {
|
||||||
|
$pk = $this->getPk();
|
||||||
|
if (is_string($pk) && $replace) {
|
||||||
|
$auto = true;
|
||||||
|
}
|
||||||
foreach ($dataSet as $key => $data) {
|
foreach ($dataSet as $key => $data) {
|
||||||
if ($replace && isset($data[$this->getPk()])) {
|
if (!empty($auto) && isset($data[$pk])) {
|
||||||
$result[$key] = self::update($data);
|
$result[$key] = self::update($data);
|
||||||
} else {
|
} else {
|
||||||
$result[$key] = self::create($data);
|
$result[$key] = self::create($data);
|
||||||
|
|||||||
Reference in New Issue
Block a user