Doctrine Ormのロゴ

Doctrine Orm

コミュニティ
fatonh
doctrine-orm

Use when creating Doctrine ORM 3 entities, associations, repositories, enums, or UUID identifiers in Symfony. Defines entity conventions, attribute mapping, fetch strategy, and repository structure. Use when the task mentions entity, Doctrine, repository, association, or mapping.

概要

公開者fatonh
リポジトリsymfony-skills
スキル名doctrine-orm
スター
36
フォーク
3
同梱ファイル
2
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 2個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    fatonhがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルDoctrine OrmをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/fatonh/symfony-skills/tree/main/skills/doctrine-orm
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/fatonh/symfony-skills.git /tmp/symfony-skills
mkdir -p .claude/skills
cp -r /tmp/symfony-skills/skills/doctrine-orm .claude/skills/doctrine-orm
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでDoctrine Ormを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にDoctrine Ormを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Doctrine Ormは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Doctrine ORM 3 (Symfony)

Entity conventions

php
#[ORM\Entity(repositoryClass: OrderRepository::class)]
#[ORM\Table(name: 'orders')]
class Order
{
    #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME, unique: true)]   // symfony/uid type
    private Uuid $id;

    #[ORM\Column(length: 255)]
    private string $customerEmail;

    #[ORM\Column(enumType: OrderStatus::class)]          // backed enum, stored as string
    private OrderStatus $status;

    /** @var Collection<int, OrderItem> */
    #[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'order', cascade: ['persist'], orphanRemoval: true)]
    private Collection $items;

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
    private \DateTimeImmutable $createdAt;

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
    private ?\DateTimeImmutable $updatedAt = null;

    // private constructor — force creation through a named factory
    private function __construct(string $customerEmail)
    {
        $this->id = Uuid::v7();                            // sortable UUID
        $this->customerEmail = $customerEmail;
        $this->status = OrderStatus::Pending;
        $this->items = new ArrayCollection();
        $this->createdAt = new \DateTimeImmutable();
    }

    public static function create(string $customerEmail): self
    {
        return new self($customerEmail);
    }

    // Behavior, not a setter
    public function addItem(Uuid $productId, int $quantity): void
    {
        $this->items->add(new OrderItem($this, $productId, $quantity));
    }

    public function getId(): Uuid { return $this->id; }
    public function getStatus(): OrderStatus { return $this->status; }
    /** @return Collection<int, OrderItem> */
    public function getItems(): Collection { return $this->items; }
}

Rules

  • IDs: symfony/uid Uuid (prefer UUID v7 — time-ordered, index-friendly). Never expose auto-increment integers in a public API.
  • Enums: #[ORM\Column(enumType: OrderStatus::class)] with a backed enum (string). Never store the ordinal/int.
  • Dates: Types::DATETIME_IMMUTABLE + \DateTimeImmutable. Never mutable \DateTime.
  • Collections: initialize in the constructor (new ArrayCollection()), typed Collection<int, X>. Never null.
  • No public setters — expose behavior methods; getters are fine.
  • Factory creation — private constructor + named static factory (Order::create()), so an entity can't be built in an invalid state.
  • declare(strict_types=1); in every file.

Associations & fetch strategy

  • #[ORM\ManyToOne] and #[ORM\ManyToMany] are LAZY by default — keep it that way. Never fetch: 'EAGER'.
  • The owning side holds the FK column (#[ORM\JoinColumn]); the inverse side uses mappedBy.
  • Keep both sides in sync with a helper on the owning aggregate.
php
// Child owns the FK
#[ORM\ManyToOne(targetEntity: Order::class, inversedBy: 'items')]
#[ORM\JoinColumn(name: 'order_id', nullable: false, onDelete: 'CASCADE')]
private Order $order;
php
// ❌ BAD — eager fetch loads the whole graph on every query
#[ORM\ManyToOne(fetch: 'EAGER')]
private Customer $customer;

Use cascade: ['persist'] deliberately; avoid cascade: ['remove'] — prefer orphanRemoval or explicit deletion so you don't accidentally wipe shared records.

Repositories

php
/** @extends ServiceEntityRepository<Order> */
final class OrderRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Order::class);
    }

    public function save(Order $order, bool $flush = false): void
    {
        $this->getEntityManager()->persist($order);
        if ($flush) {
            $this->getEntityManager()->flush();
        }
    }

    /** @return Order[] */
    public function findActiveByCustomer(string $email): array
    {
        return $this->createQueryBuilder('o')
            ->andWhere('o.customerEmail = :email')
            ->andWhere('o.status = :status')
            ->setParameter('email', $email)
            ->setParameter('status', OrderStatus::Active)
            ->getQuery()
            ->getResult();
    }
}
  • Type the repository with @extends ServiceEntityRepository<Entity> so static analysis knows the return types.
  • exists* checks: SELECT 1 … setMaxResults(1) is faster than loading the entity.
  • Never put business logic in repositories (see layered-architecture).

Value objects: embeddables & custom types

php
#[ORM\Embedded(class: Address::class)]
private Address $shippingAddress;

For single-column value objects (Email, Money), write a custom DBAL type so the model stays rich and the schema stays flat.

Gotchas

  • Agent uses fetch: 'EAGER' on associations — keep ManyToOne/ManyToMany LAZY; fetch explicitly when needed (see doctrine-query-optimization).
  • Agent uses auto-increment int IDs — use symfony/uid Uuid (v7).
  • Agent stores enums as int / uses enumType with a pure (non-backed) enum — use a string-backed enum.
  • Agent adds public setters to entities — use behavior methods + a factory.
  • Agent uses mutable \DateTime — use \DateTimeImmutable with DATETIME_IMMUTABLE.
  • Agent forgets orphanRemoval: true on owning OneToMany — orphaned child rows pile up.
  • Agent adds cascade: ['remove'] casually — prefer orphanRemoval / explicit deletes to avoid wiping shared rows.
  • Agent leaves collections uninitialized — new ArrayCollection() in the constructor.
  • Agent uses Doctrine annotations (@ORM\Entity) — use PHP 8 attributes.
  • Agent forgets the @extends ServiceEntityRepository<Entity> generic — analysis loses return types.

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Doctrine Orm」では何ができますか?

Use when creating Doctrine ORM 3 entities, associations, repositories, enums, or UUID identifiers in Symfony. Defines entity conventions, attribute mapping, fetch strategy, and repository structure. Use when the task mentions entity, Doctrine, repository, association, or mapping.

TypingMindでDoctrine Ormを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Doctrine Ormはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにDoctrine Ormをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/fatonh/symfony-skills/tree/main/skills/doctrine-ormを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Doctrine Ormを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Doctrine Ormは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもDoctrine Ormを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Doctrine Orm」は無料ですか?

はい。fatonhがGitHubでMITライセンスの下で公開しています。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇