Skip to main content
Version: v2.0 (upcoming)

ORM

config/packages/orm.php configures Doctrine ORM and registers the full suite of ORM console commands.

What it does

  • Configures a Doctrine Configuration with:
    • AttributeDriver reading entity paths from orm.entity_paths.
    • UnderscoreNamingStrategy (converts camelCase property names to snake_case columns).
    • Metadata, query, and result caches pointed at cache.pool.doctrine.
    • Proxy classes stored in orm.proxy_directory; auto-generation enabled only in debug mode.
    • Native lazy objects enabled.
  • Creates the EntityManagerInterface from the DBAL connection and configuration.
  • Wires EntityManagerProvider (used by console commands) to SingleManagerProvider.
  • Registers ORM console commands.
  • Aliases cache.pool.doctrine to cache.pool.default (override in services.php to use a separate pool).

Configuration parameters

KeyDefaultDescription
orm.entity_paths[{app.project_root}/src/Entity] (from services.php)Directories scanned by AttributeDriver for entity classes.
orm.proxy_directory{app.project_root}/var/cache/doctrineWhere Doctrine writes generated proxy class files.
cache.pool.doctrineAliased to cache.pool.defaultPSR-6 cache pool used for Doctrine metadata, query, and result caches. Override to use a dedicated pool.

Using a dedicated Doctrine cache pool

// services.php
use ForestCityLabs\Framework\Cache\Pool\PredisCachePool;
use function DI\create;
use function DI\get;

'cache.pool.doctrine' => create(PredisCachePool::class)
->constructor(get('redis.doctrine_client')),

Adding entity paths

// services.php
use function DI\add;
use function DI\string;

'orm.entity_paths' => add([
string('{app.project_root}/src/Entity'),
string('{app.project_root}/src/Module/Entity'),
]),

Console commands registered

CommandDescription
orm:schema-tool:createCreates the database schema from entity mappings.
orm:schema-tool:updateUpdates the database schema to match current mappings.
orm:schema-tool:dropDrops the database schema.
orm:generate-proxiesPre-generates proxy classes for all entities.
orm:run-dqlExecutes a DQL query and prints results.
orm:validate-schemaValidates the mapping against the database schema.
orm:infoLists all mapped entities.
orm:mapping:describeDescribes the mapping metadata for a given entity.

Dependencies

PackageDescription
doctrine/ormDoctrine Object Relational Mapper.