多个数据库,一个Doctrine Connection和一个不服从的bundle

时间:2016-04-07 18:17:41

标签: php mysql symfony doctrine-orm

奇怪的问题我与Doctrine ORM有关

我有各种各样的包,它们都包含自己的一组实体,它们都管理着自己的数据库。它们都在相同的默认连接下进行管理。

# Doctrine Configuration
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                user:     "%database_user%"
                password: "%database_password%"
                dbname:   "%database_dbname%"
                charset:  UTF8
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

由于所有托管数据库共享相同的连接,因此有意将dbname参数留空,并且定位相应的数据库和表格会在@Table注释中指定。

我的问题是三个捆绑包中只有两个可以使用了。

为了简洁起见,捆绑包是:AppBundle,BlogBu​​ndle,SalesBundle 其中每个都在{BundleName} \ Entity下管理自己的一组实体。设置非常简单,我将从每个包中共享实体的标题

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Account
 *
 * @ORM\Table(name="siteengine.account", options={"comment":"Governing User Account Storage"})
 * @ORM\Entity
 */
class Account
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

那个有效。

<?php

namespace SalesBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Client
 *
 * @ORM\Entity(repositoryClass="SalesBundle\Repository\ClientRepository")
 * @ORM\Table(name="sales.Client", options={"comment":"Main/Primary Client Storage for Sales"})
 */
class Client
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

那个也有效。

<?php

namespace BlogBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\Account;

/**
 * @ORM\Entity(repositoryClass="BlogBundle\Repository\PostRepository")
 * @ORM\Table(name="blog.posts", options={"comment":"Primary Blog Post Storage"})
 */
class Post
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

这个没有。

我的意思是&#34;不是&#34;是教义命令。我可以在任何地方使用Blog实体,并获取我想要和需要的数据,但我必须自己为博客实体手动创建表和模式,以便对此进行测试。无论出于何种原因,App和Sales捆绑都工作正常,我对它们所做的任何更改都会反映在bin/console doctrine:schema:update --dump-sql outpu中,但在任何时候,任何有关博客捆绑的内容都不会反映在同一输出中。

同样,在相同的连接下,三个捆绑包中的两个与模式工具一起工作,但是所有三个捆绑包在执行DQL命令时都有效。

我觉得,我在这里失去理智

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。而且我不喜欢结果。

经过多次游戏之后,我注意到如果我将默认连接dbname参数设置到任何一个数据库,并运行命令它确实会同步。包括博客数据库。

然后我偶然发现github project that is attempting to do exactly the same thing as me,文件也震惊了我,因为它确认了怀疑

  
      
  • 创建两个测试数据库'symfonydemo_post'和   'symfonydemo_user';
  •   
  • 您可以简单地自动构建数据库   将parameters.yml中的db名称设置为'symfonydemo_post'并运行'php   app / console doctrine:schema:update'创建表,更改   db名称为'symfonydemo_user'并重复该过程以构建   用户实体的表格。
  •   

Whelp ..我想那很酷,你可以对cli有一点控制............................ ..............

相关问题