加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Symfony2“在链中找不到类”两个捆绑关系

发布时间:2020-12-13 16:50:40 所属栏目:PHP教程 来源:网络整理
导读:为了尝试跨bundle定义一对多关系,会发生以下情况: The class ‘ManaClientBundleEntityMember’ was not found in the chain configured namespaces ManaSplitBundleEntity 更新3: 我现在看到了相互矛盾的答案,即这种关系能够而且无法实现.假设它可以
为了尝试跨bundle定义一对多关系,会发生以下情况:

The class ‘ManaClientBundleEntityMember’ was not found in the chain
configured namespaces ManaSplitBundleEntity

更新3:

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

更新2:

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

探查器中的错误消息

The target entity ‘ManaClientBundleEntityMember’ specified on
ManaSplitBundleEntityClient#members is unknown or not an entity.

因为SchemaValidator将$cmf-> isTransient($assoc [‘targetEntity’])评估为true而发生,其中成员实体中的targetEntity. PHPdoc注释表明未加载此实体的元数据.如果我理解正确,这意味着没有加载关于关系的注释.但观察变量值表明已经阅读了注释.

我完全错过了一些应该非常明显的东西吗?还是我离开了太远了?

更新1:

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

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

客户实体:

/**
 * @ORMOneToMany(targetEntity="ManaClientBundleEntityMember",mappedBy="client")
 * @ORMOrderBy({"dob" = "ASC"})
 */
protected $members;

会员实体:

/**
 * @ORMManyToOne(targetEntity="ManaSplitBundleEntityClient",inversedBy="members",cascade={"remove","persist"})
 * @ORMJoinColumn(name="cid",referencedColumnName="id")
 * 
 */
 protected $client;

学说映射:

$php app/console doctrine:mapping:info
Found 12 mapped entities:
[OK]   ManaClientBundleEntityAgency
[OK]   ManaClientBundleEntityCenter
[OK]   ManaClientBundleEntityContact
[OK]   ManaClientBundleEntityContactdesc
[OK]   ManaClientBundleEntityCounties
[OK]   ManaClientBundleEntityEthnicity
[OK]   ManaClientBundleEntityIncomehistory
[OK]   ManaClientBundleEntityIncomesrc
[OK]   ManaClientBundleEntityMember
[OK]   ManaClientBundleEntityNote
[OK]   ManaClientBundleEntityReferral
[OK]   ManaClientBundleEntityUser

$php app/console doctrine:mapping:info --em=split
Found 1 mapped entities:
[OK]   ManaSplitBundleEntityClient

解决方法

你应该看到 Using Relationships with Multiple Entity Managers

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

但是,如果您只有一个与数据库的连接和一个实体管理器,则可以管理跨捆绑关系. (这里描述:OneToMany Relation on cross project entities (Symfony2/Doctrine))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读