在链中没有发现的Symfony2“类”在两个捆绑关系 [英] Symfony2 "class not found in the chain" in two bundle relationship

查看:90
本文介绍了在链中没有发现的Symfony2“类”在两个捆绑关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在捆绑中定义一对多关系,发生以下情况:

In an attempt to define a one-to-many relationship across bundles the following occurs:


类'Mana\ClientBundle链中没有找到\Entity\Member'
配置命名空间Mana\SplitBundle\Entity

The class 'Mana\ClientBundle\Entity\Member' was not found in the chain configured namespaces Mana\SplitBundle\Entity



更新3:



现在我已经看到相互矛盾的答案,关系可以而且不能完成。假设它可以(因为在stackoverflow中的其他人似乎已经完成了),除了在AppKernel.php中注册bundle并在实体中输入注释之外,还需要什么配置? resolve_target_entity_listener 似乎没有任何作用。

Update 3:

I've now seen conflicting answers that the relationship can and cannot be accomplished. On the assumption that it can (because others here at stackoverflow seem to have done it), what configuration is required other than registering the bundles in AppKernel.php and entering the annotations in the entities? The resolve_target_entity_listener did not appear to make a difference.

嗯,我知道我在这里的深度,但这是我试图显示一个客户实体时看到的代码。

Well, I know I'm way out of my depth here, but this is what I observed while stepping through the code when trying to show a Client entity.

分析器中的错误消息


目标实体'Mana\ClientBundle\Entity\Member'指定为
Mana\SplitBundle\Entity\Client#成员是未知的或不是一个实体。

The target entity 'Mana\ClientBundle\Entity\Member' specified on Mana\SplitBundle\Entity\Client#members is unknown or not an entity.

因为SchemaValidator评估 $ cmf-> isTransient($ assoc ['targetEntity'])为true,其中MemberEntity在成员实体中。 PHPdoc注释表明该实体的元数据未加载。如果我正确理解,这意味着关于关系的注释没有加载。但是观察变量值表明注释已被读取。

occurs because SchemaValidator evaluates $cmf->isTransient($assoc['targetEntity']) to true, where the targetEntity in the Member entity. The PHPdoc comment suggests that this entity's metadata is not loaded. If I understand this correctly, that means that the annotation regarding the relationship is not loaded. But observing variable values suggests that the annotations have been read.

我完全错过了应该很痛苦的东西吗?还是我在左边的领域太远了?

Am I totally missing something that should be painfully obvious? Or am I too far out in left field?

我已经确认 doctrine:mapping:info 将检测到不正确的FQCN。数据夹具正确。对于默认和拆分连接,实体管理器和数据库连接的使用是正确的。错误仍然存​​在,可能发生在客户端实体(OneToMany或ManyToOne)中定义的任何关系。

I have confirmed that doctrine:mapping:info will detect improper FQCN. The data fixtures are correct. Use of entity managers and database-connection for both default and split connections are correct. The error persists and can occur for any of the relationships defined in the Client entity, either OneToMany or ManyToOne.

doctrine:
    dbal:
        default_connection: default
        connections:
          default:
            driver:   "%database_driver%"
            host:     "%database_host%"
            port:     "%database_port%"
            dbname:   "%database_name%"
            user:     "%database_user%"
            password: "%database_password%"
            charset:  UTF8
            mapping_types: 
                enum:       string
          split:
            driver:   "%database_driver2%"
            host:     "%database_host2%"
            port:     "%database_port2%"
            dbname:   "%database_name2%"
            user:     "%database_user2%"
            password: "%database_password2%"
            charset:  UTF8
            mapping_types: 
                enum:       string
    entity_managers:
      default:
        connection: default
        mappings:
          ManaClientBundle: ~
      split:
        connection: split
        mappings:
          ManaSplitBundle: ~



客户实体:



Client entity:

/**
 * @ORM\OneToMany(targetEntity="Mana\ClientBundle\Entity\Member", mappedBy="client")
 * @ORM\OrderBy({"dob" = "ASC"})
 */
protected $members;



会员实体:



Member entity:

 /**
 * @ORM\ManyToOne(targetEntity="Mana\SplitBundle\Entity\Client",inversedBy="members",cascade={"remove", "persist"})
 * @ORM\JoinColumn(name="cid", referencedColumnName="id")
 * 
 */
 protected $client;



教义映射:



Doctrine mapping:

$ php app/console doctrine:mapping:info
Found 12 mapped entities:
[OK]   Mana\ClientBundle\Entity\Agency
[OK]   Mana\ClientBundle\Entity\Center
[OK]   Mana\ClientBundle\Entity\Contact
[OK]   Mana\ClientBundle\Entity\Contactdesc
[OK]   Mana\ClientBundle\Entity\Counties
[OK]   Mana\ClientBundle\Entity\Ethnicity
[OK]   Mana\ClientBundle\Entity\Incomehistory
[OK]   Mana\ClientBundle\Entity\Incomesrc
[OK]   Mana\ClientBundle\Entity\Member
[OK]   Mana\ClientBundle\Entity\Note
[OK]   Mana\ClientBundle\Entity\Referral
[OK]   Mana\ClientBundle\Entity\User

$ php app/console doctrine:mapping:info --em=split
Found 1 mapped entities:
[OK]   Mana\SplitBundle\Entity\Client


推荐答案

你应该会看到< a href =https://stackoverflow.com/questions/11463517/using-relationships-with-multiple-entity-managers>使用与多个实体管理器的关系

如果您具有单独的连接和实体管理器的数据库,则交叉绑定关系不能由Doctrine管理。相反,在这种情况下,客户端实体将必须驻留在相同的模式/捆绑包中,并从外部源定期刷新。

A cross-bundle relationship cannot be managed by Doctrine if you have separate databases with separate connections and entity managers. Instead, in this case, the Client entity would have to reside in the same schema/bundle and be periodically refreshed from the external source.

但是,如果只有一个连接到数据库和一个实体管理器,您可以管理交叉关系。 (在此描述:跨项目实体的一对多关系(Symfony2 / Doctrine)

But if you have only one connection to the database and one entity manager for it you can manage cross-bundle relationships. (Described here: OneToMany Relation on cross project entities (Symfony2/Doctrine))

这篇关于在链中没有发现的Symfony2“类”在两个捆绑关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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