Question

I'm having a tough time setting up doctrine ORM configuration using Symfony2. I'm setting up the ORM files using yml.

I've looked at a couple of open source Symfony2 projects(mostly Sylius) and the norm seems to be placing Entities outsides of the bundles in a folder called Components but placing the ORM definitions in the bundles. Can anyone suggest any useful resources to help me set this up? The default seems to require my entities to be within bundles which I don't want to do because some of my entities have scope across multiple bundles.

I've noticed in the documentation you can configure entity managers individually but I can't see how the configuration options below can achieve what I'm after, especially because the entities may not all share the same prefix:

mappings:
    AcmeOrderBundle:
        type:              ~
        dir:               ~
        alias:             ~
        prefix:            ~
        is_bundle:         ~

Any help with this would be greatly appreciated and I can provide more information if necessary.

Was it helpful?

Solution

Here is an example using a couple of the options:

    entity_managers:

        games:
           connection: games
           mappings:
                CeradGameBundle: 
                    type:   yml
                    dir:    Resources/config/doctrine2
                    prefix: Cerad\Bundle\GameBundle\Doctrine\Entity

The dir points to where the orm.yml files live. As shown it is relative to the bundle. But you can replace it with an absolute path if you want.

The prefix is basically the namespace of your entities.

As far as multiple prefixes go, you can have multiple mappings for a given manager. Make one mapping per prefix.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top