Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

How do you use `object` cast handler for Entity?

オープン
#7,993 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
php
領域
backend, database

調査の方向性

property casting のドキュメントから始め、次に system/Entity/Cast/ObjectCast.php と、そこで参照されている EntityTest.php のケースを読んでください。object cast を使用して Entity を保存する例を再現し、意図された動作を特定してください。handler の使用方法とデータベースとのやり取りが、明確なテストまたはドキュメントの更新によってカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

question

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時間
マージ済み PR(30日)
59

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

codeigniter4/CodeIgniter4 のほかの issue

codeigniter4/CodeIgniter4 の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。