How do you use `object` cast handler for Entity?
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
先從 property casting 文件開始,接著閱讀 system/Entity/Cast/ObjectCast.php 以及其中參照的 EntityTest.php 案例。重現使用 object cast 儲存 Entity 的範例,並確定預期行為;當 handler 的使用方式和資料庫互動都由明確的測試或文件更新涵蓋時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
https://codeigniter4.github.io/CodeIgniter4/models/entities.html#property-casting
The object handler seems to expect the property to be set to an array.
https://github.com/codeigniter4/CodeIgniter4/blob/0cd39937d7a8dbd8074237596024adce0fe3c2af/system/Entity/Cast/ObjectCast.php#L22-L25
https://github.com/codeigniter4/CodeIgniter4/blob/0cd39937d7a8dbd8074237596024adce0fe3c2af/tests/system/Entity/EntityTest.php#L439-L449
However, when setting an array, we cannot save that Entity to the database.
$entity = new class () extends Entity {
protected $casts = [
'id' => 'int',
'active' => 'int-bool',
'memo' => 'object', // Use `object` handler
];
};
$model = new class () extends Model {
protected $table = 'users';
protected $allowedFields = [
'username', 'active', 'memo',
];
protected $useTimestamps = true;
};
$entity->fill(['username' => 'johnsmith', 'active' => false, 'memo' => ['foo', 'bar']]);
$model->save($entity); // CodeIgniter\Database\Exceptions\DatabaseException : Operand should contain 1 column(s)
How is this handler used in the first place?
- 主要語言
- 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
-
needs-triage Platform(Default)
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
[Store] RstLoader detects headings inside indented code blocks可能已有人在做 @lazerg 今天認領。 未關閉Bug Status: Needs Review Store
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
bug repo:ckeditor
難度 2/5 1-3 小時 新手友好度 78/100
-
No Code Attached Yet
難度 2/5 1-3 小時 新手友好度 72/100
joomla/joomla-cms#48611 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆