0

I'm new Symfony2 user and I need help! I have two Bundles with entities:

// My\FooBundle\Entity\Foo.php
namespace My\FooBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="foo")
 * @ORM\Entity
 */
class Foo
{

    /*...*/

    /**         
     * @ORM\OneToOne(targetEntity="My\BarBundle\Entity\Bar")
     */
    private $bar;
}

And in another bundle:

// My\BarBundle\Entity\Bar.php
namespace My\BarBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="bar")
 * @ORM\Entity
 */
class Bar
{
    /*...*/

    /**
     * @ORM\Column(name="name", nullable=false)
     */
    private $name;
}

And my config.yml:

doctrine:
    dbal:
        default_connection:   foo
        connections:
            foo:                
                dbname:   "foo"                
            bar:               
                dbname:   "bar"   
    orm:               
        entity_managers:
            foo:
                connection:       foo
                mappings:
                    MyFooBundle: ~ 
                    MyBarBundle: ~
            bar:
                connection:       bar
                mappings: 
                    MyBarBundle: ~

And SF creates Bar in Foo database. Q: How do I create a relation between two connections in this situation?

Vladowski
  • 111
  • 1
  • 5

2 Answers2

1

Remove MyBarBundle bundle from foo connection.

Udan
  • 5,429
  • 2
  • 28
  • 34
  • it show me an error, when i try to execute `doctrine:schema:update --dump-sql`: `The class 'My\BarBundle\Entity\Bar' was not found in t he chain configured namespaces My\FooBundle\Foo` – Vladowski Oct 22 '13 at 13:28
  • do you have 'use My\BarBundle\Entity\Bar' in My\FooBundle\Entity – goto Oct 22 '13 at 14:45
  • http://stackoverflow.com/questions/11463517/using-relationships-with-multiple-entity-managers – Udan Oct 22 '13 at 14:50
0

Add database name to bar entity

// My\BarBundle\Entity\Bar.php
namespace My\BarBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="bar.bar")
 * @ORM\Entity
 */
class Bar
{
    /*...*/

    /**
     * @ORM\Column(name="name", nullable=false)
     */
    private $name;
}

And following strings to config.yml:

doctrine:
    dbal:
        default_connection:   foo
        connections:
            foo:                
                dbname:   "foo"                
            bar:               
                dbname:   "bar"   
    orm:               
        entity_managers:
            foo:
                connection:       foo
                mappings:
                    MyFooBundle: ~ 
                    MyBarBundle: 
                        type:     "annotation"    
                        dir:      ..\..\My\BarBundle\Entity      
            bar:
                connection:       bar
                mappings: 
                    MyBarBundle:  
                        type:     "annotation"    
                        dir:      ..\..\My\BarBundle\Entity
Vladowski
  • 111
  • 1
  • 5