Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Formula Doctrine Bundle

Formula Doctrine Bundle Laravel Package

cryonighter/formula-doctrine-bundle

View on GitHub
Deep Wiki
Context7

Symfony bundle integrating Hibernate-style #[Formula] computed fields into Doctrine ORM entities

Frequently asked questions about Formula Doctrine Bundle
Can I use this bundle in Laravel? It says Symfony in the description.
No, this bundle is designed exclusively for Symfony applications using Doctrine ORM. Laravel uses Eloquent, so it’s incompatible. For Laravel, consider alternatives like Spatie’s Laravel Model Attributes or custom accessors with query scopes.
How do I install and set up the bundle in my Symfony project?
Run `composer require cryonighter/formula-doctrine-bundle`, then ensure the bundle is registered in `config/bundles.php`. If you use other Doctrine extensions (e.g., Gedmo), place this bundle last in the registration order to avoid conflicts.
What Laravel version of Doctrine ORM does this bundle support?
This bundle requires **Doctrine ORM 2.10+** and **Symfony 5.4+**. It does not work with Laravel’s Eloquent or native Doctrine bundles. If you’re using Laravel, check for Doctrine-specific packages like `doctrine/orm` in your `composer.json`.
Will formulas impact performance if I load entities in bulk?
Yes, formulas trigger additional SQL queries per entity by default. For bulk operations, use `HydrationMode::HYDRATE_ARRAY` or `JOIN FETCH` in DQL to batch-load formulas. Avoid N+1 queries by optimizing how entities are hydrated.
Can I use #[Formula] with PostgreSQL’s generated columns or MySQL’s computed columns?
No, this bundle provides **pure SQL/DQL computed fields** without relying on database-specific features like PostgreSQL’s `GENERATED ALWAYS AS`. It’s portable across MySQL, PostgreSQL, SQLite, etc., but lacks write-support like PostgreSQL’s updatable columns.
How do I test entities with #[Formula] attributes?
Use Doctrine’s `EntityManager` mocks or database test containers. Mock the `FormulaListener` or override `getFormulaValue()` in tests. For integration tests, ensure your test database supports the SQL expressions used in formulas.
Are there alternatives for Laravel that provide similar functionality?
For Laravel, consider **Spatie’s Laravel Model Attributes** for declarative computed fields, or **custom accessors** with query scopes. If you need SQL subqueries, use Eloquent’s `withCount()` or raw queries in accessors.
How do I cache formula results to avoid repeated SQL queries?
The bundle doesn’t include built-in caching, but you can cache formula results manually using Symfony’s Cache component or Redis. Store computed values in a transient property (e.g., `$_formulaCache`) and refresh them on entity changes.
What happens if a formula fails (e.g., invalid SQL or missing joins)?
Failed formulas throw exceptions during entity hydration. Enable Doctrine SQL logging (`doctrine.dbal.logging_enabled: true`) to debug issues. Ensure your SQL/DQL expressions are valid for your database and that referenced tables/columns exist.
Can I use #[Formula] with API Platform or other Doctrine extensions?
Yes, but register `FormulaDoctrineBundle` **last** in `config/bundles.php` to avoid conflicts with other SQL walkers (e.g., Gedmo, API Platform). Test thoroughly, as some extensions may override Doctrine’s metadata or hydration logic.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle