Say I have an aggregate root Entity with some flags which are represented by an encapsulated object EntityFlags:
class Entity
{
/** @var EntityFlags */
private $flags;
...
}
For this Entity I have a repository for this entity.
My goal is to modify flags in the DB. There are two ways I see:
- Get entity from the repository, modify flags like
$entity->getFlags()->set($name, true)and save it:$repository->save($entity). - Create an additional method in the repository, e.g.
modifyFlags(EntityId $id, EntityFlags $flags)
I think the first way is redundant. But it also seems wrong to use repository for partial entity updates like in the 2nd way. WhatWhich way is the correct one? Maybe I missed something?