0

我是 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;
}

我的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: ~

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

4

2 回答 2

1

从连接中删除MyBarBundle捆绑包。foo

于 2013-10-22T13:18:50.053 回答
0

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

// 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
于 2013-10-23T07:08:51.497 回答