Skip to content

Doctrine🔗

Installation🔗

1
composer require orm

Configuration🔗

Base configuration of a project using XML mapping:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: 'mariadb-10.3.11'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: xml
                dir: '%kernel.project_dir%/config/doctrine/entity'
                prefix: 'App\Domain\Model'
                alias: App

Note: Be sure your driver and server_version match your VM config.

Note: Change your mapping prefix according to your project.

Makefile🔗

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Reset database, play all migrations, update schema and load fixtures
db:
    make db-create
    make db-update
    make db-fixtures

## Create database schema
db-create:
    bin/console doctrine:database:drop --force --no-interaction --if-exists
    bin/console doctrine:database:create --if-not-exists

## Update database schema
db-update:
    bin/console doctrine:migration:migrate --no-interaction
    bin/console doctrine:schema:update --force

## Generate a migration diff between the schema and the existing migrations
db-diff:
    make db-create
    bin/console doctrine:migration:migrate --no-interaction
    bin/console doctrine:migration:diff --no-interaction
    bin/console doctrine:migration:migrate --no-interaction
    make db-fixtures

## Generate fixtures
db-fixtures:
    bin/console doctrine:fixtures:load --no-interaction

Last update: December 20, 2024