← スキル一覧に戻る

symfony-skapi-entity-relation
by Swoking
Claude Code plugin pour projets Symfony StarterKit
⭐ 0🍴 0📅 2026年1月19日
SKILL.md
name: symfony-sk:api-entity-relation description: Add a relation between two existing entities. Use when linking entities with ManyToOne, OneToMany, or ManyToMany relationships. allowed-tools: Read, Write, Edit, Glob, Grep
API Entity Relation Skill
Mission
Add a relationship between two existing Doctrine entities.
Relation Types
ManyToOne (N:1)
One entity references another. Most common.
Task -> Event (many tasks belong to one event)
OneToMany (1:N)
Inverse of ManyToOne. Collection on the "one" side.
Event -> Tasks (one event has many tasks)
ManyToMany (N:N)
Both sides have collections. Requires join table.
Event <-> Tags (events have tags, tags have events)
Templates
ManyToOne (owning side)
Add to the entity that holds the foreign key:
use App\Entity\<Target>;
#[ORM\ManyToOne(targetEntity: <Target>::class)]
#[ORM\JoinColumn(nullable: false)]
private ?<Target> $<target> = null;
public function get<Target>(): ?<Target>
{
return $this-><target>;
}
public function set<Target>(?<Target> $<target>): static
{
$this-><target> = $<target>;
return $this;
}
OneToMany (inverse side)
Add to the entity that has the collection:
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
// In constructor
$this-><targets> = new ArrayCollection();
// Property
#[ORM\OneToMany(targetEntity: <Target>::class, mappedBy: '<source>', cascade: ['persist', 'remove'])]
private Collection $<targets>;
public function get<Targets>(): Collection
{
return $this-><targets>;
}
public function add<Target>(<Target> $<target>): static
{
if (!$this-><targets>->contains($<target>)) {
$this-><targets>->add($<target>);
$<target>->set<Source>($this);
}
return $this;
}
public function remove<Target>(<Target> $<target>): static
{
if ($this-><targets>->removeElement($<target>)) {
if ($<target>->get<Source>() === $this) {
$<target>->set<Source>(null);
}
}
return $this;
}
ManyToMany
Owning side:
#[ORM\ManyToMany(targetEntity: <Target>::class, inversedBy: '<sources>')]
#[ORM\JoinTable(name: '<source>_<target>')]
private Collection $<targets>;
Inverse side:
#[ORM\ManyToMany(targetEntity: <Source>::class, mappedBy: '<targets>')]
private Collection $<sources>;
Process
- Identify relation type (ManyToOne, OneToMany, ManyToMany)
- Identify owning side (the one with the foreign key)
- Add property + methods to owning side
- Add inverse property + methods if bidirectional
- Add constructor initialization for collections
- Run
dsuto update schema
After Modification
ssh <host> "docker exec <code>-api ./scripts/dsu"
Checklist
- Relation type identified
- Owning side determined
- Property added with ORM attributes
- Getter/setter added
- Constructor initializes collections (if applicable)
- Inverse side added (if bidirectional)
-
mappedBy/inversedBymatch property names - Schema updated via
dsu
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です