使用不同实体管理员的不同捆绑包的实体中的问题 [英] Issues in entities from different bundles using different entity managers

查看:139
本文介绍了使用不同实体管理员的不同捆绑包的实体中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:



我准备了一个tar.gz,一旦解压缩,运行后./bin/vendors安装无法通过php脚本/ createAll加载灯具.PHP。在tar.gz中,有2个捆绑包使用两个不同的连接,每个人都有自己的数据库。



我认为Symfony2无法正确管理它们。如果你看看脚本/ createAll.php会看到symfony如何加载两个装置,但是如果你删除一个随机的夹具(Var_.php或Foo_.php无关紧要,一切都运行正常,这在我看来symfony无法正确管理实体。)



LINK: http://www.2shared.com/file/2u4GhFVX/SymfonyTestCasetar.html



我想告诉 Symfony2 为不同的 Bundle
目录
使用不同的实体管理器,所以我的config.yml看起来像:

  orm:
auto_generate_proxy_classes:%kernel.debug%
default_entity_manager:
entity_managers:
默认值:
连接:默认
映射:
myVendorURLCoreBundle:〜
myVendormyBundleBundle:〜
myVendormyBundleFooBu ndle:
前缀:myVendor\myBundleFooBundle\Entity
类型:注释
is_bundle:true
dir:/ Entity
formacions:
连接:formacions
映射:
myVendormyBundleFooBarBundle:
前缀:myVendor\myBundleFooBarBundle\View
类型:注释
is_bundle:false
dir :%kernel.root_dir%/ .. / src / myVendor / myBundleFooBarBundle / View

当使用不同目录中的实体之间的关系时,我会收到由 vendor / doctrine / lib / Doctrine / ORM / Mapping / MappingException.php在第142行引起的以下错误 / p>

类FRJPC\SalleUrlFormacionsBundle\Entity\EspecialitatContingut不是有效的实体或映射的超级cla ss



这个问题是在供应商名称打破命名空间之前有时候\。真的很奇怪



以下是彼此之间的链接实体:

 


命名空间myVendor\myBundleFooBundle\Entity;

使用Doctrine\ORM\Mapping作为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;
}

第二实体:

 

命名空间myVendor\myBundleFooBarBundle\Entity;

使用Doctrine\ORM\Mapping作为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:两个实体在同一个捆绑包和相同的目录中时,就像魅力一样。

解决方案

所有这些Foos和Bars与一个带有真实姓名的错误消息相结合,使得它有点难以跟踪,并留下了发布的代码与实际代码不符的可能性。 FooBarBundle / View似乎是不太可能存储实体的地方。



无论如何,给定的实体经理(如formacions)需要能够查看所有相关实体,包括参与关系的人。它看起来像你在foo包中定义了A,在B包中定义B,并且它们都互相交叉引用?



从你的配置中,我看不到formacion em可以看到你的A实体,同样我也看不到默认的em可以看到B实体。关系中的完全限定类名称不足以共享实体主义元数据。因此,错误消息。



我真的很高兴被证明是错误的。令人沮丧的是不能做这些事情。


Edit:

I've prepared a tar.gz which once uncompressed and after running ./bin/vendors install fails to load the fixtures through php scripts/createAll.php. In the tar.gz there are 2 bundles using 2 different connections everyone with its own database.

I think Symfony2 fails to manage them properly. If you take a look at scripts/createAll.php will see how symfony fails to load both fixtures, but if you remove a random fixture (it doesn't matter Var_.php or Foo_.php everything runs fine, which seems to me that symfony is failing to manage entities correctly.)

LINK: http://www.2shared.com/file/2u4GhFVX/SymfonyTestCasetar.html

i want to tell Symfony2 to use different entity managers for different Bundle directories so my config.yml looks like:

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"

The problem is when using relationships between the entities in the different directories i get the following error caused by vendor/doctrine/lib/Doctrine/ORM/Mapping/MappingException.php at line 142

Class FRJPC\SalleUrlFormacionsBundle\Entity\EspecialitatContingut is not a valid entity or mapped super class

The probem is that sometimes "\" before the vendor name breaks the namespace. It's really strange.

Here is how i i link entities between each other:



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;
}

Second entity:


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;
}

Does any one has a clue on how should i link each entity?

PD: Both entities work like charm when they're in the same bundle and same directory.

解决方案

All these Foos and Bars combined with an error message with a real name make it a bit difficult to follow and leaves open the possibility that posted code really doesn't match the actual code. The FooBarBundle/View seems to be an unlikely place to store entities.

In any event a given entity manager such as formacions needs to be able to see all the relevant entities including those involved in relations. It looks like you defined A in the foo bundle and B in the bar bundle and they both cross reference each other?

From your config, I don't see how the formacion em can see your A entity and likewise I don't see how the default em can see the B entity. The fully qualified class name in the relation is not enough to share the entity doctrine metadata. Hence the error messages.

I'd would actually be glad to be proven wrong about this. It's a bit frustrating not to be able to do these sorts of things.

这篇关于使用不同实体管理员的不同捆绑包的实体中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆