【发布时间】:2012-03-08 22:58:20
【问题描述】:
编辑:
我准备了一个 tar.gz,它一旦解压缩并且在运行 ./bin/vendors install 后无法通过 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 是 不是有效的实体或映射的超类
问题是有时供应商名称前的“\”会破坏命名空间。这真的很奇怪。
这是我如何在彼此之间链接实体:
命名空间 myVendor\myBundleFooBundle\Entity; 使用 Doctrine\ORM\Mapping 作为 ORM; /** * @ORM\Entity(repositoryClass="myVendor\myBundleFooBundle\Repository\ARepository") * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") * @ORM\Table( name="a" ) */ A级 { /** * @ORM\ID * @ORM\Column( type="integer", length="4" ) * @ORM\GeneratedValue( 策略="AUTO" ) */ 私人 $id; /** * @ORM\ManyToOne(targetEntity="\myVendor\myBundleFooBarBundle\Entity\B", inversedBy="a", cascade={"persist"}) * @ORM\JoinColumn( name="FooBar", nullable=true, referencedColumnName="FooBar", onDelete="CASCADE" ) */ 私人 $fooBar; }第二个实体:
命名空间 myVendor\myBundleFooBarBundle\Entity; 使用 Doctrine\ORM\Mapping 作为 ORM; /** * @ORM\Entity(repositoryClass="myVendor\myBundleFooBarBundle\Repository\ARepository") * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") * @ORM\Table( name="a" ) */ B类 { /** * @ORM\ID * @ORM\Column( type="integer", length="4" ) * @ORM\GeneratedValue( 策略="AUTO" ) */ 私人 $id; /** @ORM\OneToMany( targetEntity="\myVendor\myBundleFooBundle\Entity\EspecialitatContingut", mappedBy="fooBar" ) */ 私人 $a; }有没有人知道我应该如何链接每个实体?
PD:当两个实体在同一个包和同一个目录中时,它们的工作方式就像魅力一样。
【问题讨论】:
标签: symfony doctrine doctrine-orm