改进saveall方法

This commit is contained in:
thinkphp
2016-08-20 14:47:23 +08:00
parent 3454e8a13c
commit 5cc1448a83

View File

@@ -730,7 +730,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
* @access public
* @param array $dataSet 数据
* @param boolean $replace 是否自动识别更新和写入
* @return array|false
* @return array
*/
public function saveAll($dataSet, $replace = true)
{
@@ -738,8 +738,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$db = $this->db();
$db->startTrans();
try {
$pk = $this->getPk();
if (is_string($pk) && $replace) {
$auto = true;
}
foreach ($dataSet as $key => $data) {
if ($replace && isset($data[$this->getPk()])) {
if (!empty($auto) && isset($data[$pk])) {
$result[$key] = self::update($data);
} else {
$result[$key] = self::create($data);