Skip to content

Commit

Permalink
Merge pull request #487 from hermann8u/fix-slug-uniqueness
Browse files Browse the repository at this point in the history
Fix slug uniqueness
  • Loading branch information
TomasVotruba committed Jan 6, 2020
2 parents a099e2e + bffec25 commit 2cf2585
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Repository/DefaultSluggableRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ public function isSlugUniqueFor(SluggableInterface $sluggable, string $uniqueSlu
->select('e')
->from($entityClass, 'e')
->select('COUNT(e)')
->andWhere('e.id != :id')
->andWhere('e.slug = :slug')
->setParameter('id', $sluggable->getId())
->setParameter('slug', $uniqueSlug);

$id = $sluggable->getId();
if ($id !== null) {
$queryBuilder
->andWhere('e.id != :id')
->setParameter('id', $id);
}

return ! (bool) $queryBuilder->getQuery()
->getSingleScalarResult();
}
Expand Down

0 comments on commit 2cf2585

Please sign in to comment.