我有一个实体A,它有一个与B的关系ManyToOne,但是A和B不属于同一个DB模式。
实体'A‘属于MyBundle捆绑包,实体'B’属于MyOtherBundle捆绑包。
官方文档解释了如何使用不同的连接:多个模式=多个实体管理器。但在我的情况下,我想加入这两个实体。
通过执行以下操作:
$this->objEm->getRepository('MyBundle:MyEntity')->find($id);或
$this->objEm->getRepository('MyBundle:MyEntity')->getMyResult($id);我只调用了我的一个存储库,我猜他无法获得另一个,因为在我的config.yml中,我只能选择一个连接。
doctrine:
dbal:
connections:
connection1:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_schema1_user%"
password: "%database_schema1_password%"
service: "%database_service%"
charset: "Windows-1252"
connection2:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_schema2_user%"
password: "%database_schema2_password%"
service: "%database_service%"
charset: "Windows-1252"
orm:
entity_managers:
em1:
connection: connection1
mappings:
MyBundle: ~
MyOtherBundle: ~
em2:
connection: connection2
mappings:
MyOtherBundle: ~结果:哇,看起来好像出了什么问题。
1/1ReflectionException:类FQCN\Of\MyBundle\Entity\B不存在...
“我知道它不存在,伙计,我希望你现在看看好的地方:像FQCN\Of\MyOtherBundle\Entity\B”
如何才能将路径强制到我的实体'B'?
发布于 2012-12-20 00:23:45
问题解决了!它与数据库、模式或注释完全没有任何关系。
在实体A中,我的一个personnal setter在参数中强制键入:
public function setB(B $objB) { //... }..。我忘了使用B的FQCN!这就是它使用A的one的原因。
下一次我不会在注释中声明FQCN,以迫使我在类的开头使用它!:)
发布于 2012-12-19 04:38:42
如果您的模式位于同一数据库中,则只需将实体的表定义为
Bundle\Entity\Class:
type: entity
table: schema.class(yaml)
您不需要指定第二个连接。当模式被明确指出时,这些连接在规则2中可以完美地工作。
如果您的模式位于不同的数据库中,那么您将遇到一些麻烦,因为每个连接都将查询两个数据库;对于多个记录连接,每个条目都将执行一个连接,这意味着您将执行与结果集中的对象数量成比例的大量查询(BAD)。
https://stackoverflow.com/questions/13938008
复制相似问题