Doctrine 2.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 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.