Doctrine Mapping in Symfony2 using YAML

Ivancodescratch picture Ivancodescratch · Oct 1, 2014 · Viewed 8.5k times · Source

I have a question regarding YAML configuration of Doctrine in Symfony2.

I have created an entity via "doctrine:generate:entity", and chose YAML as the mapping format. This didn't add any metadata on ../Entity/"MyEntity".php, which would allow me to update or create my schema.

As an example, if I run

./app/console doctrine:schema:create

it fails, saying:

[RuntimeException]                                                 
Bundle "MySuperBundle" does not contain any mapped entities.

My automapping is already set to "true".

If I choose to use annotation config this would not be a problem.

Did I miss something? Are there any extra steps that I should take?

Thank you in advance, regards,

Ivan

Answer

frumious picture frumious · Oct 1, 2014

I just had a fun time looking at the Doctrine config initialisation code. What I found was:

  • Using auto_mapping results in various defaults being set for the single default entity manager; it leaves the type value as false
  • If type is false the config code looks into the default directory for likely config files, and as soon as it finds a file of a valid extension it decides that that's the way config is being done, in the order xml, yml, php
  • If it doesn't find any of those it assumes annotation

Do you have anything else at all in the Bundle/Resources/config/doctrine folder? If so, it might be throwing off the auto-detection.

That aside, basically if you've used defaults, and have some entity classes and valid config, what you're doing should be working without any additional config. You've said "auto_mapping" is true, but have you changed any other bit of Doctrine config?

It might be an idea to try configuring stuff explicitly, e.g. as described in the Symfony Doctrine docs, go from default config

doctrine:
    dbal:
        driver:   "%database_driver%"
        #etc

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

to explicit

doctrine:
    dbal:
        driver:   "%database_driver%"
        #etc

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: false
        mappings:
            MySuperBundleName:
                type: yml
                dir: Resources/config/doctrine