PHPackages                             kikwik/doctrine-relation-count-bundle - 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. kikwik/doctrine-relation-count-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

kikwik/doctrine-relation-count-bundle
=====================================

Manage counter as database property for doctrine relations

v1.0.2(1y ago)0193MITPHPPHP &gt;=8.1

Since May 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kikwik/doctrine-relation-count-bundle)[ Packagist](https://packagist.org/packages/kikwik/doctrine-relation-count-bundle)[ RSS](/packages/kikwik-doctrine-relation-count-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

Kikwik/DoctrineRelationCountBundle
==================================

[](#kikwikdoctrinerelationcountbundle)

Manage counter as database property for doctrine relations

Installation
------------

[](#installation)

1. require the bundle

```
#!/bin/bash
composer require kikwik/doctrine-relation-count-bundle
```

Usage
-----

[](#usage)

- Add an integer field in the related classes wich will contain the count value, setter is not required.

```
#[ORM\Entity(repositoryClass: FamigliaRepository::class)]
class Famiglia
{
    #[ORM\Column]
    private int $numProdotti = 0;

    public function getNumProdotti(): int
    {
        return $this->numProdotti;
    }
}
```

```
#[ORM\Entity(repositoryClass: SimboloRepository::class)]
class Simbolo
{
    #[ORM\Column]
    private int $numProdotti = 0;

    public function getNumProdotti(): int
    {
        return $this->numProdotti;
    }
}
```

- Add the `#[CountableEntity]` attribute on top of your child class
- Add the `#[CountableRelation]` attribute on the ManyToOne or ManyToMany relations which you would count
- Set the `targetProperty` parameter to the count property in the related class

```
use Kikwik\DoctrineRelationCountBundle\Attribute\CountableEntity;
use Kikwik\DoctrineRelationCountBundle\Attribute\CountableRelation;

#[ORM\Entity(repositoryClass: ProdottoRepository::class)]
#[CountableEntity]
class Prodotto
{
    #[ORM\ManyToOne(inversedBy: 'prodotti')]
    #[CountableRelation(targetProperty: 'numProdotti')]
    private ?Famiglia $famiglia = null;

    #[ORM\ManyToMany(targetEntity: Simbolo::class, inversedBy: 'prodotti')]
    #[CountableRelation(targetProperty: 'numProdotti')]
    private Collection $simboli;
}
```

Custom updater
--------------

[](#custom-updater)

If you need to use a customized query for the counter update you can define a `updateCountableRelation`method in your child repository

```
class ProdottoRepository extends ServiceEntityRepository
{
    public function updateCountableRelation(object $localObject, string $relationName, object $relatedObject, string $relatedProperty)
    {
        $dql = sprintf('UPDATE %s related set related.%s = (SELECT COUNT(local.id) FROM %s local WHERE local.%s = :id AND local.isActive = 1) WHERE related.id = :id',
                        get_class($relatedObject),
                        $relatedProperty,
                        get_class($localObject),
                        $relationName,
                    );

        $query = $this->getEntityManager()->createQuery($dql)
            ->setParameter('id', $relatedObject->getId());
        $query->execute();
    }
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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

Every ~6 days

Total

3

Last Release

708d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bdd98919c8ee6645e854e72f8c6b76c503e12fd10078fb34ae1668cb2bd6d1a?d=identicon)[kikwik](/maintainers/kikwik)

---

Top Contributors

[![kikwik](https://avatars.githubusercontent.com/u/58590255?v=4)](https://github.com/kikwik "kikwik (6 commits)")

### Embed Badge

![Health badge](/badges/kikwik-doctrine-relation-count-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/kikwik-doctrine-relation-count-bundle/health.svg)](https://phpackages.com/packages/kikwik-doctrine-relation-count-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[hautelook/alice-bundle

Symfony bundle to manage fixtures with Alice and Faker.

19519.4M34](/packages/hautelook-alice-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[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)

PHPackages © 2026

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