In a previous blog post about "Getting easier", Nathan made this useful comment:

**Great stuff**! I applaud this direction. Is there any chance the
location for Doctrine schema files could be shortened? I made files like
this for each entity:
`src/Mycompany/MyBundle/Resources/config/doctrine/metadata/orm/Mycompany.MyBundle.Entity.Orderset.dcm.yml`
But I'm like, "are you serious? What happened to `config/schema.yml`?" I
like Larry Wall's philosophy about Perl - "make easy things easy and hard
things possible".

We have heard you Nathan! In the upcoming beta2, we have shortened the path by removing the unneeded metadata/orm/ part. So, defining the mapping for your Orderset class can now be done in src/Mycompany/MyBundle/Resources/config/doctrine/Mycompany.MyBundle.Entity.Orderset.orm.yml instead of src/Mycompany/MyBundle/Resources/config/doctrine/metadata/orm/Mycompany.MyBundle.Entity.Orderset.dcm.yml.

That's slightly better but not that much, isn't it? Unfortunately, Doctrine2 enforces the one file per class rule, and forces the file to be named after the fully qualified class name. But as I used to be a Perl developer, and because shorter file names are always better, I've tried to find some ways to get around the rule.

It turned out to be quite easy and DoctrineBundle now supports the definition of several mapping metadata into one single file. So, you can also define your Orderset class mapping data in src/Mycompany/MyBundle/Resources/config/doctrine/mapping.orm.yml. This is even shorter than before and of course totally optional. You can mix and match both possibilities into a single bundle: define most of your mapping data into one main file, and still use individual files for entities that have many metadata information.

But what about the possibility to define all your mapping data into a central location? If you are like me, you want to be able to reuse your Model outside of a Symfony2 context; and so you don't want to store your Entity classes and their mapping data under a specific bundle. So, what about storing everything in app/config/mapping.orm.yml for instance? Well, that's also possible and here is a simple working configuration:

doctrine:
    orm:
        mappings:
            global:
                type:   yml
                dir:    %kernel.root_dir%/config
                prefix: Blog\Entity

The good news is that the doctrine:generate:entities command is also able to deal with it natively:

./app/console doctrine:generate:entities Blog/Entity --path=src/

Say good bye to your old src/Mycompany/MyBundle/Resources/config/doctrine/metadata/orm/Mycompany.MyBundle.Entity.Orderset.dcm.yml file and enjoy using app/config/mapping.orm.yml.

Feedback is the key to improve Symfony2.

UPDATE: As of Symfony2 beta2, mapping for a single entity must be done using the short name: src/Mycompany/MyBundle/Resources/config/doctrine/Orderset.orm.yml.

Published in #Living on the edge