Jakub Matczak
Jakub Matczak

Reputation: 15676

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. ;-)

Upvotes: 3

Views: 1220

Answers (2)

romaricdrigon
romaricdrigon

Reputation: 1587

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.

Upvotes: 6

Sylvain Guilbert
Sylvain Guilbert

Reputation: 722

yes it's in conf files :

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

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: false //default was true
        mappings:
            MySuperBundleName:
                type: yml
                dir: Resources/somewhereElse/doctrine // your specific directory

Upvotes: 0

Related Questions