0
votes

Edit:

I've prepared a tar.gz which once uncompressed and after running ./bin/vendors install fails to load the fixtures through php scripts/createAll.php. In the tar.gz there are 2 bundles using 2 different connections everyone with its own database.

I think Symfony2 fails to manage them properly. If you take a look at scripts/createAll.php will see how symfony fails to load both fixtures, but if you remove a random fixture (it doesn't matter Var_.php or Foo_.php everything runs fine, which seems to me that symfony is failing to manage entities correctly.)

LINK: http://www.2shared.com/file/2u4GhFVX/SymfonyTestCasetar.html

i want to tell Symfony2 to use different entity managers for different Bundle directories so my config.yml looks like:

orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager:   default
    entity_managers:
        default:
            connection: default
            mappings:
                myVendorURLCoreBundle: ~
                myVendormyBundleBundle: ~
                myVendormyBundleFooBundle:
                    prefix: "myVendor\myBundleFooBundle\Entity"
                    type: annotation
                    is_bundle: true
                    dir: "/Entity"
        formacions:
            connection: formacions
            mappings:
                myVendormyBundleFooBarBundle:
                    prefix: "myVendor\myBundleFooBarBundle\View"
                    type: annotation
                    is_bundle: false
                    dir: "%kernel.root_dir%/../src/myVendor/myBundleFooBarBundle/View"

The problem is when using relationships between the entities in the different directories i get the following error caused by vendor/doctrine/lib/Doctrine/ORM/Mapping/MappingException.php at line 142

Class FRJPC\SalleUrlFormacionsBundle\Entity\EspecialitatContingut is not a valid entity or mapped super class

The probem is that sometimes "\" before the vendor name breaks the namespace. It's really strange.

Here is how i i link entities between each other:



namespace myVendor\myBundleFooBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity( repositoryClass="myVendor\myBundleFooBundle\Repository\ARepository" )
 * @ORM\ChangeTrackingPolicy( "DEFERRED_EXPLICIT" )
 * @ORM\Table( name="a" )
 */
class A
{
    /**
     * @ORM\Id
     * @ORM\Column( type="integer", length="4" )
     * @ORM\GeneratedValue( strategy="AUTO" )
     */
    private $id;

    /** 
     * @ORM\ManyToOne( targetEntity="\myVendor\myBundleFooBarBundle\Entity\B", inversedBy="a", cascade={"persist"} )
     * @ORM\JoinColumn( name="FooBar", nullable=true, referencedColumnName="FooBar", onDelete="CASCADE" )
     */
    private $fooBar;
}

Second entity:


namespace myVendor\myBundleFooBarBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity( repositoryClass="myVendor\myBundleFooBarBundle\Repository\ARepository" )
 * @ORM\ChangeTrackingPolicy( "DEFERRED_EXPLICIT" )
 * @ORM\Table( name="a" )
 */
class B
{
    /**
     * @ORM\Id
     * @ORM\Column( type="integer", length="4" )
     * @ORM\GeneratedValue( strategy="AUTO" )
     */
    private $id;

        /** @ORM\OneToMany( targetEntity="\myVendor\myBundleFooBundle\Entity\EspecialitatContingut", mappedBy="fooBar" ) */
        private $a;
}

Does any one has a clue on how should i link each entity ?

PD: Both entities work like charm when they're in the same bundle and same directory.

1

1 Answers

3
votes

All these Foos and Bars combined with an error message with a real name make it a bit difficult to follow and leaves open the possibility that posted code really doesn't match the actual code. The FooBarBundle/View seems to be an unlikely place to store entities.

In any event a given entity manager such as formacions needs to be able to see all the relevant entities including those involved in relations. It looks like you defined A in the foo bundle and B in the bar bundle and they both cross reference each other?

From your config, I don't see how the formacion em can see your A entity and likewise I don't see how the default em can see the B entity. The fully qualified class name in the relation is not enough to share the entity doctrine metadata. Hence the error messages.

I'd would actually be glad to be proven wrong about this. It's a bit frustrating not to be able to do these sorts of things.