我的网名十三个字不信你数数 2022-12-27 14:29 采纳率: 0%
浏览 111

新增数据method not exist:think\db\Query->saveAll

问题遇到的现象和发生背景

批量新增

遇到的现象和发生背景,请写出第一个错误信息

method not exist:think\db\Query->saveAll

用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
$res = Db::name('invoice_rate')->saveAll();//在model里面使用saveAll

//这是报错
[0] Exception in Query.php line 200
method not exist:think\db\Query->saveAll
            return call_user_func_array([$this, 'where'], $args);
        } elseif ($this->model && method_exists($this->model, 'scope' . $method)) {
            // 动态调用命名范围
            $method = 'scope' . $method;
            array_unshift($args, $this);

            call_user_func_array([$this->model, $method], $args);
            return $this;
        } else {
            throw new Exception('method not exist:' . ($this->model ? get_class($this->model) : static::class) . '->' . $method);
        }
    }

    /**
     * 扩展查询方法
     * @access public
     * @param  string|array  $method     查询方法名
     * @param  callable      $callback
     * @return void


运行结果及详细报错内容
[0] Exception in Query.php line 200
method not exist:think\db\Query->saveAll
            return call_user_func_array([$this, 'where'], $args);
        } elseif ($this->model && method_exists($this->model, 'scope' . $method)) {
            // 动态调用命名范围
            $method = 'scope' . $method;
            array_unshift($args, $this);

            call_user_func_array([$this->model, $method], $args);
            return $this;
        } else {
            throw new Exception('method not exist:' . ($this->model ? get_class($this->model) : static::class) . '->' . $method);
        }
    }

    /**
     * 扩展查询方法
     * @access public
     * @param  string|array  $method     查询方法名
     * @param  callable      $callback
     * @return void


我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%

在当前问题上面进行了一系列的测试,save isupdate saveall等等都是会报类似的错误

我想要达到的结果,如果你需要快速回答,请尝试 “付费悬赏”
  • 写回答

1条回答 默认 最新

  • Python小叮当 2022-12-29 17:25
    关注

    单独针对这一行代码而言
    $res = Db::name('invoice_rate')->saveAll();

    你看看saveAll()里面是不是要传递参数,又或者不能操作?

    一版 DB::name(‘xxx’) 返回的是一个数据库对象,保存的时候不知道是不是更新,如果是更新的话,应该有个查询条件

    ps:看看tp的手册 数据库模块

    评论

报告相同问题?

问题事件

  • 创建了问题 12月27日

悬赏问题

  • ¥20 有偿,学生成绩信息管理系统
  • ¥15 Arduino电机和openmv连接异常
  • ¥15 Arcgis河网分级报错
  • ¥200 java+appium2.1+idea
  • ¥20 请帮我做一个EXE的去重TXT文本
  • ¥15 工价表引用工艺路线,应如何制作py和xml文件
  • ¥15 根据历史数据,推荐问题类型
  • ¥15 需要仿真图,简单的二阶系统实例
  • ¥15 stm32光控照明仿真
  • ¥15 使用人工智能的方法生成满足一定统计参数要求的随机数序列