PHPackages                             jivochat/entity-exists-constraint - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. jivochat/entity-exists-constraint

ActiveLibrary[Database &amp; ORM](/categories/database)

jivochat/entity-exists-constraint
=================================

Symfony validator for checking if Entity Exist

0.1(5y ago)37MITPHPPHP ^7.3

Since Oct 24Pushed 5y ago2 watchersCompare

[ Source](https://github.com/JivoChat/entity-exists-constraint)[ Packagist](https://packagist.org/packages/jivochat/entity-exists-constraint)[ RSS](/packages/jivochat-entity-exists-constraint/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Symfony validator for checking if Entity Exist
==============================================

[](#symfony-validator-for-checking-if-entity-exist)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

This validator verifies that an Entity actually exists in a database. You can use it in different DTO objects. For instance in request object or service dto's

```
namespace App\Requests;

use JivoChat\Validator\Constraint\EntityExists;
use Symfony\Component\Validator\Constraints as Assert;

final class RequestDto
{
    /**
     * @Assert\NotBlank
     * @EntityExists(entity="Entity\User")
     *
     * @var int User's id property
     * In this case validator will found User primary key. If key has the same name as the parameter (userId),
     * validator will try to found record in database (where userId = $userId).
     * If primary key has different name, exception will be thrown
     */
    private $userId;

    /**
     * @Assert\NotBlank
     * @EntityExists(entity="Entity\Post", mapping={"postId": "messageId"}, exception=true)
     *
     * @var int
     * Let's assume that Post has composite primary key userId, postId. Because of the mapping, the validator knows that
     * it must take the value from $messageId and set it to the postId parameter in the query.
     * For the userId parameter it will try to find parameter with the same name or with name from mapping
     * in the dto object. If parameter will be found, validator will take value. if not, exception will be thrown.

     * Parameter "exception" tells what to do if entity was not found. If it is true, exception will be thrown
     */
    private $messageId;

     /**
     * @Assert\NotBlank
     * @EntityExists(entity="Entity\Transaction", mapping={"ownerId": "userId"}, persistentManager="global")
     *
     * @var int
     * Let's assume that Transaction has primary key transactionId. In this case mapping says to add parameter ownerId
     * in query and take value from dto parameter $userId (where transactionId = $transactionId AND ownerId = $userId)
     *
     * Parameter "persistentManager" tells which entity manager using in this case. By default using manager which
     * contains entity or default manager.
     */
    private $transactionId;

    public  function getUserId(): int
    {
        return $this->userId;
    }

    public  function getMessageId(): int
    {
        return $this->messageId;
    }

    public  function getTransactionId(): int
    {
        return $this->transactionId;
    }
}
```

You can use default EntityExists constrain from package or make your own to change default parameters.

```
class EntityExists extends Constraint
{
    /** @var string */
    public $message = 'Entity "%entity%" with parameter "%value%" does not exist.';
    // Violation message. You can use parameters %entity%, %value%, %parameters%

    /** @var string */
    public $entity = '';

    /** @var array */
    public $mapping = [];

    /** @var null|string */
    public $persistentManager = null;

    /** @var bool */
    public $exception = false;
    // If it is true, exception will be thrown. It is good then you want to show 404 page

    public function throwException(): void
    {
        throw NotFound::entity($this->entity);
    }
}
```

Full example
------------

[](#full-example)

```
 $dto = new RequestDto();
 $dto->setUserId($request->request->get('user_id'));
 $dto->setMessageId($request->request->get('message_id'));
 $dto->setTransactionId($request->request->get('transaction_id'));

 $violationList = $this->validator->validate($requestDto);
 if ($violationList->count()) {
    ...
 }
```

Install
-------

[](#install)

```
composer require jivochat/entity-exists-constraint
```

Then register the services with:

```
services:
  JivoChat\Validator\Constraint\EntityExistsValidator:
      arguments: [ '@doctrine' ]
      tags: [ 'validator.constraint_validator' ]
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2025d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6667136?v=4)[oldy](/maintainers/oldy)[@Oldy](https://github.com/Oldy)

---

Top Contributors

[![oldy777](https://avatars.githubusercontent.com/u/913048?v=4)](https://github.com/oldy777 "oldy777 (2 commits)")

---

Tags

constraintsdoctrinephpsymfonyvalidator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jivochat-entity-exists-constraint/health.svg)

```
[![Health](https://phpackages.com/badges/jivochat-entity-exists-constraint/health.svg)](https://phpackages.com/packages/jivochat-entity-exists-constraint)
```

###  Alternatives

[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[bolt/core

🧿 Bolt Core

585142.5k54](/packages/bolt-core)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1022.4k](/packages/rcsofttech-audit-trail-bundle)[intaro/custom-index-bundle

Annotation and command for control entity custom indexes

27836.1k](/packages/intaro-custom-index-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
