[Model] Upsert problem with data validation, allowed fields, dates defined
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
使用所示的 TestModel、其 upsert 呼叫和 MySQL 設定重現該行為,然後追蹤 upsert 如何處理驗證、允許的欄位、軟刪除和時間戳記。完成的標準是:無效資料在查詢前產生驗證錯誤、不允許的欄位被排除,且產生的 SQL 與預期輸出一致。
由索引模型根據 Issue 內容生成。
描述
PHP Version
7.4
CodeIgniter4 Version
4.3.2
CodeIgniter4 Installation Method
Composer (as dependency to an existing project)
Which operating systems have you tested for this bug?
Windows, Linux
Which server did you use?
apache
Database
MySQL (ver. 8.0.28)
What happened?
Upsert does not work correctly with the model.
Allowed fields, validation rules, dates (created_at, updated_at) are defined within the model, this does not apply to the query.
The model should throw validation errors first!
Steps to Reproduce
class TestModel extends BaseModel
{
protected $table = 'table';
protected $allowedFields = [
'item_id', 'item_quantity'
];
protected $validationRules = [
'item_id' => 'required|is_natural_no_zero',
'item_quantity' => 'required|numeric',
];
protected $useSoftDeletes = true;
protected $protectFields = true;
protected $useTimestamps = true;
}
$model = new TestModel();
$model->upsert([
'item_id' => "string data", //validation is not correct
'item_quantity' => 99, //everything ok
'col1' => "string data", //not in allowed fields
]);
//check validation errors
$model->errors();
$model->db->getLastQuery()->getQuery();
Expected Output
INSERT INTO `table` (`item_quantity`, `created_at`, `updated_at`)
VALUES (99, unix_timestamp, unix_timestamp)
ON DUPLICATE KEY UPDATE
`table`.`item_quantity` = VALUES(`item_quantity`),
`table`.`updated_at` = VALUES(`updated_at`)
Anything else?
No response
- 主要語言
- PHP
- 星號
- 6k
- 分支
- 2k
- 平均合併
- 1 天 22 小時
- 30 天內合併 PR
- 59
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
codeigniter4/CodeIgniter4 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
codeigniter4/CodeIgniter4#10616 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 35/100
codeigniter4/CodeIgniter4#10618 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 62/100
codeigniter4/CodeIgniter4#10617 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 25/100
codeigniter4/CodeIgniter4#10615 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 48/100
codeigniter4/CodeIgniter4#10589 · 3 則留言 ·
維護者通常 1 天內回覆
查看 codeigniter4/CodeIgniter4 的全部 Issue
相似的 Issue
-
sync-en
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
sync-en
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 4 天內回覆
-
Перевод устарел
難度 1/5 1 小時以內 新手友好度 85/100
-
bug
難度 2/5 半天 新手友好度 76/100
m3ue/m3u-editor#1604 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
femiwiki/docker-mediawiki#1497 ·
維護者通常 1 天內回覆