Skip to main content
2 of 5
deleted 1 character in body; added 1 character in body

Can the DDD repository modify entity in the DB without an entity object?

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.

My goal is to modify flags in the DB. There are two ways I see:

  1. Get entity from the repository, modify flags like $entity->getFlags()->set($name, true) and save it: $repository->save($entity).
  2. Create an additional method in the repository, e.g. modifyFlags(EntityId $id, EntityFlags $flags)

I think first way is redundant. But it also seems wrong to use repository for partial entity updates like in 2nd way. What way is the correct one? Maybe I missed something?

Thanks in advance.