Has Many (One-to-Many)
The HasMany
relationship links one entity to multiple related entities. For example, if each user can have multiple posts, this relationship can be annotated in the User
entity.
app/Entities/User.php
<?php
declare(strict_types=1);
namespace App\Entities;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\Relation\HasMany;
use Illuminate\Support\Collection;
#[Entity]
class User
{
#[Column(type: 'primary')]
private string $id;
#[HasMany(target: App\Entities\Post::class)]
private Collection $posts;
}
💡
Detailed explanation of One-to-Many (HasMany) relationships in CycleORM documentation.