add set root ids

This commit is contained in:
Yisroel Baum 2026-05-25 21:42:38 +03:00
parent a87c98a729
commit 7736b88802
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 36 additions and 3 deletions

View file

@ -10,6 +10,8 @@ interface ElementRepository
public function find(int $id): ?Element;
public function findRootBySet(DomainSet $set): ?Element;
/**
* @return Element[]
*/

View file

@ -35,6 +35,16 @@ class EloquentElementRepository implements ElementRepository
return $model === null ? null : $this->toDomain($model);
}
public function findRootBySet(DomainSet $set): ?Element
{
$model = ElementModel::where('set_id', $set->getId())
->whereNull('parent_element_id')
->orderBy('id')
->first();
return $model === null ? null : $this->toDomain($model);
}
/**
* @return Element[]
*/