cryonighter/formula-doctrine-bundle
Pros:
#[Formula]) without manual query logic in repositories/services, improving separation of concerns.COUNT, SUM, AVG).Cons:
GENERATED ALWAYS AS).formula-doctrine dependency).GENERATED columns, this is pure SQL, so portability is high.#[Formula] attributes to entities.EntityManager::find() or Repository::find(), formulas will automatically execute.SELECT e FROM Entity e) must ensure formulas are included in the result set or handled separately.Customer::getOrders() where orderCount is a formula).JOIN FETCH or batch loading (HydrationMode::HYDRATE_ARRAY + manual hydration).#[Formula] values could inject SQL if not sanitized.doctrine.dbal.logging_enabled: true) for troubleshooting.EntityManager mocks or database test containers.orderCount not reflecting real-time changes)?#[Formula]?tenantOrderCount) are needed.getOrderCount() in entities/services).#[Formula] (read-only, SQL-expressible logic).Customer.orderCount).COUNT, SUM) before complex subqueries.#[Formula] in small batches.@Cache on repositories).JOIN FETCH or batch loading to mitigate N+1 issues.Sluggable, Tree) may conflict if they also modify metadata.composer require cryonighter/formula-doctrine-bundle
config/bundles.php:
Cryonighter\FormulaDoctrineBundle\FormulaDoctrineBundle::class => ['all' => true],
#[Formula] attributes to entities:
#[ORM\Entity]
class Customer {
#[Formula('(SELECT COUNT(*) FROM orders o WHERE o.customer_id = {this}.id)')]
public int $orderCount;
}
How can I help you explore Laravel packages today?