【发布时间】:2012-12-11 16:16:57
【问题描述】:
使用 Symfony-2.1 和 Doctrine-2.3。我有多个数据库,需要进行跨数据库连接,所以我遵循了以下建议:
- Multiple database connection in Doctrine2 and Zend framework
- Using Relationships with Multiple Entity Managers
并设置多个连接和一个实体管理器。这里是app/config/config.yml:
doctrine:
dbal:
default_connection: db1
connections:
db1:
driver: pdo_mysql
host: 127.0.0.1
dbname: db1
db2:
driver: pdo_mysql
host: 127.0.0.1
dbname: db2
orm:
default_entity_manager: default
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
default:
auto_mapping: true
mappings:
FirstBundle:
type: annotation
dir: Model
prefix: NoiseLabs\FirstBundle\Model
SecondBundle:
type: annotation
dir: Model
prefix: NoiseLabs\SecondBundle\Model
FirstBundle中的实体类:
namespace NoiseLabs\FirstBundle\Model;
/**
* @ORM\Entity
* @ORM\Table(name="db1.table1")
*/
class FirstEntity
{
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
SecondBundle中的实体类:
namespace NoiseLabs\SecondBundle\Model;
/**
* @ORM\Entity
* @ORM\Table(name="db2.table2")
*/
class SecondEntity
{
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="NoiseLabs\FirstBundle\Model\FirstEntity")
* @ORM\JoinColumn(name="firstId", referencedColumnName="id", onDelete="CASCADE")
*/
protected $first;
}
现在,问题是app/console doctrine:schema:update --dump-sql 仅检测(默认连接)db1.tables 中的架构更改。如果我将默认连接设置为db2,它只会输出与db2.tables相关的sql。
我已经检查了app/console doctrine:mapping:info,所有实体类都在映射中。
这是 Doctrine/Symfony 的限制还是我需要调整我的配置?谢谢。
【问题讨论】:
标签: php symfony doctrine doctrine-orm