Php Symfony 2中不同连接之间的关系

Php Symfony 2中不同连接之间的关系,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我是新的Symfony2用户,我需要帮助! 我有两个实体包: // 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(targetEnt

我是新的Symfony2用户,我需要帮助! 我有两个实体包:

// 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;
}
在另一个包中:

// 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;
}
和my config.yml:

SF在Foo数据库中创建Bar。
Q:在这种情况下,如何在两个连接之间创建关系?

foo
连接中删除
MyBarBundle
包。

将数据库名称添加到实体中

// 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;
}
以及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

它向我显示了一个错误,当我尝试执行
原则:模式:更新--dump sql
在链配置的命名空间My\FooBundle\Entity\Bar中找不到类“My\BarBundle\Entity\Bar”
在My\FooBundle\Entity中是否有“use My\BarBundle\Entity\Bar”
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