PHPackages                             cryonighter/formula-doctrine - 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. cryonighter/formula-doctrine

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

cryonighter/formula-doctrine
============================

Hibernate-style attribute #\[Formula\] computed fields for Doctrine ORM entities

1.1.4(2w ago)042↓100%1MITPHPPHP &gt;=8.2

Since Apr 30Pushed 2w agoCompare

[ Source](https://github.com/cryonighter/formula-doctrine)[ Packagist](https://packagist.org/packages/cryonighter/formula-doctrine)[ Docs](https://github.com/cryonighter/formula-doctrine)[ RSS](/packages/cryonighter-formula-doctrine/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (9)Used By (1)

Formula Doctrine
================

[](#formula-doctrine)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5d79a49155d1cac2e28ad9fbc8fcee61118f4de01473ef702323c064b5ef21ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372796f6e6967687465722f666f726d756c612d646f637472696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cryonighter/formula-doctrine)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/45e6261b58c2d2e6327afff06897c9f7517d4150b2841c58f06357e21eed0702/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6372796f6e6967687465722f666f726d756c612d646f637472696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cryonighter/formula-doctrine)

Hibernate-style `#[Formula]` computed fields for Doctrine ORM 3 entities.

Adds support for read-only, SQL-computed entity properties populated via subqueries, aggregations and joins — without N+1 queries.

```
#[ORM\Entity]
class Customer
{
    #[Formula('(SELECT COUNT(*) FROM orders o WHERE o.customer_id = {this}.id)')]
    public int $orderCount = 0;
}
```

Requirements
------------

[](#requirements)

- **PHP &gt;= 8.2.0** but the latest stable version of PHP is recommended

Install
-------

[](#install)

### Symfony

[](#symfony)

If you are using Symfony, install the bundle instead — it wires everything automatically via Symfony DI:

```
composer require cryonighter/formula-doctrine-bundle
```

See [cryonighter/formula-doctrine-bundle](https://github.com/cryonighter/formula-doctrine-bundle)for installation and configuration instructions.

### Standalone

[](#standalone)

If you use another framework or write in bare PHP:

```
composer require cryonighter/formula-doctrine
```

Bootstrap the stack manually when creating your `EntityManager`:

```
