/symfony-skills:doctrine-ormfrom symfony-skills
Defines Doctrine ORM 3 entity conventions, attribute mapping, associations, and repository structure for Symfony projects. Use when creating entities, repositories, enums, or UUID identifiers.
Ships in symfony-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
#[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; }
}
symfony/uid Uuid (prefer UUID v7 — time-ordered, index-friendly). Never expose auto-increment integers in a public API.#[ORM\Column(enumType: OrderStatus::class)] with a backed enum (string). Never store the ordinal/int.Types::DATETIME_IMMUTABLE + \DateTimeImmutable. Never mutable \DateTime.new ArrayCollection()), typed Collection<int, X>. Never null.Order::create()), so an entity can't be built in an invalid state.declare(strict_types=1); in every file.#[ORM\ManyToOne] and #[ORM\ManyToMany] are LAZY by default — keep it that way. Never fetch: 'EAGER'.#[ORM\JoinColumn]); the inverse side uses mappedBy.// Child owns the FK
#[ORM\ManyToOne(targetEntity: Order::class, inversedBy: 'items')]
#[ORM\JoinColumn(name: 'order_id', nullable: false, onDelete: 'CASCADE')]
private Order $order;
// ❌ 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.
/** @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();
}
}
@extends ServiceEntityRepository<Entity> so static analysis knows the return types.exists* checks: SELECT 1 … setMaxResults(1) is faster than loading the entity.layered-architecture).#[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.
fetch: 'EAGER' on associations — keep ManyToOne/ManyToMany LAZY; fetch explicitly when needed (see doctrine-query-optimization).int IDs — use symfony/uid Uuid (v7).enumType with a pure (non-backed) enum — use a string-backed enum.\DateTime — use \DateTimeImmutable with DATETIME_IMMUTABLE.orphanRemoval: true on owning OneToMany — orphaned child rows pile up.cascade: ['remove'] casually — prefer orphanRemoval / explicit deletes to avoid wiping shared rows.new ArrayCollection() in the constructor.@ORM\Entity) — use PHP 8 attributes.@extends ServiceEntityRepository<Entity> generic — analysis loses return types.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
doctrine-orm, symfony-entities, uuid, entity-mapping, repository-pattern
17 skills in this plugin
/api-platform-resourcesUse when exposing data through API Platform 4 — defining #[ApiResource], operations, DTO resources, state providers/processors, serialization groups, filters, and pagination. Use when the task mentions API Platform, ApiResource, state processor, or exposing an entity as a REST/GraphQL endpoint.
/bundle-organizationUse when structuring a Symfony project's src/ directory, organizing code into modules, configuring services, or deciding where a class belongs. Covers the modular monolith layout, service configuration, and config/ conventions for Symfony 7 (Flex, no app bundle).
/console-commandsUse when creating or refactoring Symfony console commands — never extends Command. On Symfony 8.1+ put #[AsCommand] on a method of a service class (even for a single command); on 7.x use the invokable attribute class. Also covers typed CLI inputs via value resolvers and #[MapInput] DTOs. Use when the task mentions console command, #[AsCommand], bin/console, #[Argument], #[Option], or a CLI task.
npx claudepluginhub fatonh/symfony-skills --plugin symfony-skillsOther plugins' skills for the same job