1
votes

I try to use Doctrine in Symfony 2.5 with an XML configuration for the entity mapping.

I have a namespaced class Bar: ACME\TestBundle\Entity\Foo\Bar

As I have many entities they can't all reside in the ACME\TestBundle\Entity namespace, but must be put into sub-namespaces.

Creating the entities is no problem, but I can't figure out where to put the ORM XML configuration files.

I tried Resources/config/doctrine/Foo/Bar.orm.xml, which doesn't find the mapping file:

$ php app/console doctrine:schema:create --dump-sql
No Metadata Classes to process.

I tried Resources/config/doctrine/Bar.orm.xml, which ignores the additional Foo namespace unter Entity, although the full namespace is correctly given in Bar.orm.xml in the name element.

$ php app/console doctrine:schema:create --dump-sql                  
[Doctrine\Common\Persistence\Mapping\MappingException] 
Class 'ACME\TestBundle\Entity\Bar' does not exist  

What am I missing? What is the correct place for the XML mapping file to reside for these namespaced classes?

1
Try with Foo.Bar.orm.xml.Damian Polac
@user3749178 is correct. The file mapping file goes under Resources/config/doctrine. It's sort of a two way mapping. Even though the mapping file contains the full name of the entity, the system needs to be able to find the mapping file based on the entity name. Not sure where this is documented. I figured it out some time ago by looking at the error messages. It's possible to use different mapping directories as well but it's painful. symfony.com/doc/current/reference/configuration/…Cerad

1 Answers

1
votes

Using @user3749178 suggestion of Foo.Bar.orm.xml works and is the easiest way to solve the problem though all the mapping files end up in one directory.

It's also possible to have individual directories for everything based on:

http://symfony.com/doc/current/reference/configuration/doctrine.html#mapping-configuration

Here is an example configuration:

doctrine:

  orm:
    default_entity_manager:       default
    auto_generate_proxy_classes: %kernel.debug%

    entity_managers:

    default:
      connection: default
      mappings:
        foo1: 
          prefix: Cerad\Bundle\ProjectGameBundle\Doctrine\Entity\Foo1
          type:   yml
          dir:    src/ProjectGameBundle/Doctrine/EntityMapping/Foo1
          is_bundle: false
        foo2: 
          prefix: Cerad\Bundle\ProjectGameBundle\Doctrine\Entity\Foo2
          type:   yml
          dir:    src/ProjectGameBundle/Doctrine/EntityMapping/Foo2
          is_bundle: false

You basically specify one mapping for each directory containing entities.