8

I'm new to Symfony 4

I use Doctrine an I want to use yaml entity mapping. So i configured the file doctrine.yaml and change type:annotation to type:yml.

And when I tried php bin/console make:entity, there is no yaml mapping file generated linked to this entity

this is my doctrine.yaml file:

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: '5.7'
        charset: utf8mb4

        # With Symfony 3.3, remove the `resolve:` prefix
        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: yml
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
gp_sflover
  • 3,460
  • 5
  • 38
  • 48
Ny Aina
  • 83
  • 1
  • 1
  • 6

1 Answers1

10

An example of mapping following your needs:

Change the file name including the "orm" text doctrine.orm.yaml, and take a look at the dir option in the example below (that follows your needs):

App:
    is_bundle: false
    type: yml
    # "dir" in this case must be pointed where are stored your doctrine files (can be anywhere inside the project dir)
    dir: "%kernel.project_dir%/config/doctrine"
    prefix: App\Entity

Reference: Doctrine yaml mapping (v2.6 current)

gp_sflover
  • 3,460
  • 5
  • 38
  • 48
  • @redigaffi link updated for the current version and thanks for notifying me. – gp_sflover Jun 22 '18 at 12:05
  • I have the same problem in symfony 5.1 with annotations and unfortunately I can't find a solution with your solution.... – Alex Aug 12 '20 at 00:28
  • @Alex open a question on SO BUT remember that yaml driver was deprecated and removed from version 3.0 so it is strongly recommended to use another mapping driver like xml – gp_sflover Aug 12 '20 at 08:35
  • yes, I made my question yesterday: https://stackoverflow.com/questions/63367323/symfony-5-1-bundle-migration-result-in-no-mapping-information-to-process yaml is deprecated? all my symfony 5.1 web skeleton came configured with yaml by default! Should I change it? – Alex Aug 12 '20 at 10:21
  • @Alex yes is deprecated as mapping driver in Doctrine (read the reference link in my answer). – gp_sflover Aug 12 '20 at 10:54