top-think / top-think/think-orm

Model::update()不返回是否操作成功,真的是蛋疼。

Open
#281 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
437
Forks
188
PR merge metrics
No merged PRs in 30d

Description

https://github.com/top-think/think-orm/blob/1af5d8d82a6a928ba19ea3dba70fd0cf7f2129ac/src/Model.php#L880

实在想不通,返回$model本身的意义何在。链式操作吗,但我还真没用过这个链式操作。

Model::where($where)->update($date)->dowhat();?;
即使真有这种需求,赋值到一个变量就行了。

$model = new Model;
$model->where($where)->update($data);
$model->dowhat();

相反的,用模型更新的时候,为了知道操作是否成功,不得不写很多代码。

$model = new Model;
$res = $model->isUpdate(true, $where)->save($data);

再简便点,但总觉得有点怪怪的。

$res = (new Model)->isUpdate(true, $where)->save($data);

1.Model::where($where)->update($data)->dowhat();

2.$model = Model::where($where)->update($data);
$model->dowhat();

谁能举个栗子,讲一下什么情况会用到这两种用法?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Model::update() entry point in src/Model.php around line 880, then compare it with the isUpdate(true, $where)->save($data) usage shown in the issue. Determine and document the intended return value and the valid use cases for chaining or checking update success; the issue does not name tests to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.