Symfony – skip check with method for specific entity object

I have a issue that I am trying to figure out for few days now.

I have wrote an overlapping method which check if the dates I entered overlap with data existing in a database. The method works for all objects.

What I want to accomplish is to skip the entity with the specific ID I found with first function and check every other row in database except the entity with that ID.

Does anyone has an idea how can I accomplish that?

public function editEntity(
    int $id,
    DateTime $startDate,
    DateTime $endDate,
    string $name,
): MyEntity {

    /** @var MyEntity $entityObject */
    $entityObject = $this->entityManager->getRepository(MyEntity::class)->find($id);

    if (empty($entityObject)) {
        throw new Exception('Entity not found.');

    if ($this->overlap(
    )) {
        throw new Exception('Dates ovelap!');



    return $entityObject;

I want to skip the check for ID that is found by doctrine ->find() method.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *