gpt4 book ai didi

php - 两个捆绑关系中的 Symfony2 "class not found in the chain"

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:41:42 26 4
gpt4 key购买 nike

在尝试跨束定义一对多关系时,会发生以下情况:

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 似乎没有什么不同。

更新 2:

好吧,我知道我在这里超出了我的深度,但这是我在尝试显示客户端实体时单步执行代码时观察到的结果。

分析器中的错误信息

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']) 为真,其中成员实体中的 targetEntity。 PHPdoc 注释表明未加载该实体的元数据。如果我理解正确,那就意味着没有加载关于关系的注释。但是观察变量值表明注释已被阅读。

我是否完全遗漏了一些本应显而易见的东西?还是我在左外野太远了?

更新 1:

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

配置.yml:

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: ~

客户端实体:

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

成员实体:

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

原则映射:

$ 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

最佳答案

你应该看到 Using Relationships with Multiple Entity Managers

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

但是如果您只有一个到数据库的连接和一个实体管理器,您就可以管理跨束关系。 (此处描述:OneToMany Relation on cross project entities (Symfony2/Doctrine))

关于php - 两个捆绑关系中的 Symfony2 "class not found in the chain",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15981639/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com