Skip to content

Do not flush in the repository #1327

Closed
@lyrixx

Description

@lyrixx

ATM, the generated code is:

    public function add(Message $entity, bool $flush = true): void
    {
        $this->_em->persist($entity);
        if ($flush) {
            $this->_em->flush();
        }
    }

This is a bad idea:

  • it's confusing: one may thing it will flush only the new message (it's not!)
  • flush should be done in the most outside layer of the application (controller, command, message handler) to avoid flushing invalid data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions