Doctrine 2.0 一对多模式验证问题

发布于 2024-10-31 05:10:07 字数 486 浏览 7 评论 0原文

class Account
{
...
/*
* @OneToMany(targetEntity="Address", mappedBy="account");
*/
private $addresses;
...
}

class Address
{
...
/**
* @ManyToOne(targetEntity="Account", inversedBy="addresses")
* @JoinColumn(name="account_id", referencedColumnName="id")
*/
private $account;
...
}

当我运行控制台命令来验证架构时:

[映射] 失败 - 实体类“Entity\Address”映射无效: * 关联Entity\Address#account指的是反面 字段 Entity\Account#addresses 不存在

为什么?

class Account
{
...
/*
* @OneToMany(targetEntity="Address", mappedBy="account");
*/
private $addresses;
...
}

class Address
{
...
/**
* @ManyToOne(targetEntity="Account", inversedBy="addresses")
* @JoinColumn(name="account_id", referencedColumnName="id")
*/
private $account;
...
}

When i run console command to validate schema:

[Mapping] FAIL - The entity-class 'Entity\Address' mapping is invalid:
* The association Entity\Address#account refers to the inverse side
field Entity\Account#addresses which does not exist

Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最冷一天 2024-11-07 05:10:07

我认为 Doctrine 注释阅读器使用 php 的 Reflection API,特别是 getDocComment 来读取注释。这意味着您的文档块注释必须以 /** 开头,否则它们将被忽略。您的 $addresses 属性注释以 /* 开头,因此不会被拾取。

I think the Doctrine annotation reader uses php's Reflection API, specifically getDocComment to read the annotations. That means your doc block comments must begin with /** otherwise they will be ignored. Your $addresses property annotation begins with /* so it won't get picked up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文