Skip to main content
4 of 5
personal stuff removed // http://meta.stackoverflow.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts
gnat
  • 20.5k
  • 29
  • 117
  • 309

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 the first way is redundant. But it also seems wrong to use repository for partial entity updates like in the 2nd way. What way is the correct one? Maybe I missed something?