关于数据完成和手动设定字段优先级的疑问?

浏览:295 发布日期:2018/11/14 分类:ThinkPHP5专区
大致看了一下源代码,使用saveAll保存数据时候,如果手动设置了model中已经定义的数据完成字段,优先级仍然是以模型中设定的数据完成为准,代码如下:

模型定义:<?php
namespace app\common\model;

use think\Model;

class Product extends Model
{
  protected $insert = ['insert_date'];
  protected $type   = [
    'insert_date' => 'timestamp'
  ];

  protected function setInsertDateAttr()
  {
    return time();
  }
}
批量插入:$model = new Product;
$insert = [];
for ($data as $item) {
  $insert[] = [
    'title'   => $item['title'],
    'content' => $item['content'],
    'insert_date' => $item['insert_date'], // 这里设置的内容不生效
  ];
}
$model->saveAll($insert);
Model::save() 应该也是如此。想问的是,除了插入之后再手动更新的方案,怎么样让手动设置的内容生效?
最佳答案
评论( 相关
后面还有条评论,点击查看>>