dt246813579 2019-06-17 07:16 采纳率: 0%
浏览 28

Doctrine的ODM可以在不声明类型的情况下引用一个文档吗?

I'm using Doctrine 2.10 with Symfony 4. I can see in the documentation for Doctrine's ODM references that a referenceMany relationship can store different types of documents in references by omitting the targetDocument option:

/* @Document */
Class User
{
    /* @ReferenceMany(targetDocument="Account") */
    private accounts = [];
}

becomes

/* @Document */
Class User
{
    /* @ReferenceMany */
    private accounts = [];
}

It seems that the same can't be achieved with the referenceOne relationship. When I use referenceOne without the targetDocument option, I get a mapping exception:

Class '' does not exist

Ideally I'd like to be able to use the mappedBy and inversedBy options so that the Account document owns the relationship, and is able to reference either a User or a Company, which share some properties. The following doesn't work, but is there a way to achieve what it represents?

/* @Document */
class User
{
    /* @ReferenceMany(targetDocument="Account", mappedBy="owner") */
    private $accounts = [];
}

/* @Document */
class Company
{
    /* @ReferenceMany(targetDocument="Account", mappedBy="owner") */
    private $accounts = [];
}

/* @Document */
class Account
{
    /* @ReferenceOne(inversedBy="accounts") */
    private $owner;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用