Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I organize Doctrine YAML mappings in subfolders?

I have custom mapping settings in my Symfony3 project for Doctrine entities like this:

MyModel:
    type: yml
    dir: %kernel.root_dir%/../src/AppBundle/Resources/config/doctrine/MyModel
    prefix: MyProject\MyModel\Model
    is_bundle: false

Let's assume I have an entity MyProject\MyModel\Model\SubNamespace\MyEntity. Now, I have to put its yml mapping in %kernel.root_dir%/../src/AppBundle/Resources/config/doctrine/MyModel/SubNamespace.MyEntity.orm.yml, and it works fine.

Can I configure Doctrine to be able to organize mapping files in subfolders instead of file names being a concatenation of parts of namespace after prefix?

In this case if would be %kernel.root_dir%/../src/AppBundle/Resources/config/doctrine/MyModel/SubNamespace/MyEntity.orm.yml

The reason is that mapping directory is growing and it's getting hard to find any particular file inside.

Of course, it's not a solution to make a configuration for every subfolder. ;-)

like image 644
Jakub Matczak Avatar asked Dec 14 '25 15:12

Jakub Matczak


1 Answers

Looking at the source code, there's nothing to handle subfolders. But then the trick could be to add each folder in a different "mapping", as far I know those don't have to stick to your Symfony bundles:

doctrine:
    # ...
    orm:
        # ...
        mappings:
            AcmeBundleFoo:
                type: yml
                dir: AcmeBundle/Resources/doctrine/Foo
            AcmeBundleBar:
                type: yml
                is_prefix: false # you are free to let Symfony guess it or to be explicit
                dir: AcmeBundle/Resources/doctrine/Bar

A little verbose, but it should work given yout folder structure is src/AcmeBundle/Resources indeed.

like image 155
romaricdrigon Avatar answered Dec 17 '25 13:12

romaricdrigon