codeigniter4 / codeigniter4/CodeIgniter4

Dev: Make getInsertID() more consistent with save()

未關閉
#9,233 4 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
PHP
星號
6k
分支
2k
平均合併
1 天 11 小時
30 天內合併 PR
73

描述

### PHP Version

8.2, 8.3

### CodeIgniter4 Version

latest

### CodeIgniter4 Installation Method

Composer (using `codeigniter4/appstarter`)

### Which operating systems have you tested for this bug?

macOS, Linux

### Which server did you use?

fpm-fcgi

### Database

MaraiaDB

### What happened?

Not exactly a bug, but not really a FR either. See this forum thread: https://forum.codeigniter.com/showthread.php?tid=91800&pid=421782#pid421782

Essentially I'm offering to PR a change to `\System\Model::update()` that would set an instance's `$insertID` property the same way `\System\Model::insert()` does so that the behaviour of `save()` is more consistent.

Currently `\System\Model::getInsertID()` only returns a value if a `save()` does an insert. The logic needed to handle that works against the elegance provided by `save()`.

### Steps to Reproduce

Use `\System\Model::save()`

### Expected Output

Best case, `\System\Model::getInsertID()` will return the "affected ID" after `\System\Model::save()` regardless of which action occurred.

### Anything else?

I'm stoked contribute to core, but I didn't want to spend the time on a PR if there is no desire to change this behaviour. Please advise.

I can write the update to the docs too if I'm pointed in the right direction to do so.

貢獻指南

開啟貢獻指南

研究方向

Read the forum thread, then compare System Model's save(), insert(), update(), and getInsertID() behavior. Confirm the intended affected-ID semantics before changing anything; done means save() exposes the expected ID consistently for both insert and update paths, with coverage for each path.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
mariadb, php
領域
backend, database
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。