Help us improve
Share bugs, ideas, or general feedback.
From symfony-sk
Add a relation between two existing entities. Use when linking entities with ManyToOne, OneToMany, or ManyToMany relationships.
npx claudepluginhub joshuarweaver/cascade-code-languages-misc-1 --plugin swoking-symfony-sk-pluginHow this skill is triggered — by the user, by Claude, or both
Slash command
/symfony-sk:skills/api-entity-relationThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Add a relationship between two existing Doctrine entities.
Evolve Symfony Doctrine models and schema safely with integrity, performance, and rollout discipline. Use for designing entity relations, schema evolution, and improving Doctrine correctness/performance.
Creates p5.js generative art with seeded randomness, noise fields, and interactive parameter exploration. Use for algorithmic art, flow fields, or particle systems.
Share bugs, ideas, or general feedback.
Add a relationship between two existing Doctrine entities.
One entity references another. Most common.
Task -> Event (many tasks belong to one event)
Inverse of ManyToOne. Collection on the "one" side.
Event -> Tasks (one event has many tasks)
Both sides have collections. Requires join table.
Event <-> Tags (events have tags, tags have events)
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;
}
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;
}
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>;
dsu to update schemassh <host> "docker exec <code>-api ./scripts/dsu"
mappedBy / inversedBy match property namesdsu