编辑:
我准备了一个tar.gz,一旦解压缩,运行后./bin/vendors安装无法通过php scripts/createAll.php
加载灯具 . 在tar.gz中有2个包使用2个不同的连接,每个连接都有自己的数据库 .
我认为Symfony2无法正确管理它们 . 如果你看看scripts / createAll.php会看到symfony如何加载两个灯具,但如果你删除一个随机夹具(无关紧要Var_.php或Foo_.php一切运行正常,在我看来symfony无法正确管理实体 . )
链接:http://www.2shared.com/file/2u4GhFVX/SymfonyTestCasetar.html
我想告诉 Symfony2
使用不同的 entity managers
用于不同的 Bundle directories
所以我的config.yml看起来像:
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
myVendorURLCoreBundle: ~
myVendormyBundleBundle: ~
myVendormyBundleFooBundle:
prefix: "myVendor\myBundleFooBundle\Entity"
type: annotation
is_bundle: true
dir: "/Entity"
formacions:
connection: formacions
mappings:
myVendormyBundleFooBarBundle:
prefix: "myVendor\myBundleFooBarBundle\View"
type: annotation
is_bundle: false
dir: "%kernel.root_dir%/../src/myVendor/myBundleFooBarBundle/View"
问题是当使用不同目录中的实体之间的关系时,我得到由 vendor/doctrine/lib/Doctrine/ORM/Mapping/MappingException.php at line 142
引起的以下错误
类FRJPC \ SalleUrlFormacionsBundle \ Entity \ EspecialitatContingut不是有效实体或映射超类
在供应商名称破坏命名空间之前,有时“是” . 真的很奇怪 .
以下是我如何在彼此之间链接实体:
namespace myVendor\myBundleFooBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity( repositoryClass="myVendor\myBundleFooBundle\Repository\ARepository" )
* @ORM\ChangeTrackingPolicy( "DEFERRED_EXPLICIT" )
* @ORM\Table( name="a" )
*/
class A
{
/**
* @ORM\Id
* @ORM\Column( type="integer", length="4" )
* @ORM\GeneratedValue( strategy="AUTO" )
*/
private $id;
/**
* @ORM\ManyToOne( targetEntity="\myVendor\myBundleFooBarBundle\Entity\B", inversedBy="a", cascade={"persist"} )
* @ORM\JoinColumn( name="FooBar", nullable=true, referencedColumnName="FooBar", onDelete="CASCADE" )
*/
private $fooBar;
}
第二实体:
namespace myVendor\myBundleFooBarBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity( repositoryClass="myVendor\myBundleFooBarBundle\Repository\ARepository" )
* @ORM\ChangeTrackingPolicy( "DEFERRED_EXPLICIT" )
* @ORM\Table( name="a" )
*/
class B
{
/**
* @ORM\Id
* @ORM\Column( type="integer", length="4" )
* @ORM\GeneratedValue( strategy="AUTO" )
*/
private $id;
/** @ORM\OneToMany( targetEntity="\myVendor\myBundleFooBundle\Entity\EspecialitatContingut", mappedBy="fooBar" ) */
private $a;
}
有没有人知道我应该如何链接每个实体?
PD: Both entities work like charm when they're in the same bundle and same directory.
1 回答
所有这些Foos和Bars结合带有真实姓名的错误消息使得它有点难以理解并且留下了发布代码与实际代码不匹配的可能性 . FooBarBundle / View似乎不太可能存储实体 .
无论如何,诸如formacions之类的给定实体经理需要能够看到所有相关实体,包括涉及关系的实体 . 看起来你在foo包中定义了A,在bar bundle中定义了B,它们彼此交叉引用?
从您的配置中,我看不出形式的em如何看到您的A实体,同样我也看不到默认的em如何看到B实体 . 关系中的完全限定类名不足以共享实体教义元数据 . 因此错误消息 .
我真的很高兴被证明是错的 . 不能做这些事情有点令人沮丧 .