Zend 框架,原则 2 @ManyToOne
我基本上遵循了这个http://www.zendcasts。 com/one-to-many-with-doctrine-2/2011/03/ 该步骤的教程(可以从那里下载源代码)。一切正常,所以我有 2 个实体 - 购买和用户。如果我查询用户一切都很好,但如果我查询购买,就像这样:
$entityManager->createQuery('select p from ZC\Entity\Purchase p where p.id = 1')->execute();
我会得到一个致命错误:
Fatal error: require() [function.require]: Failed opening required 'C:\xampp\htdocs\CoChces\application/../library/CC/Entity/Proxy\CCEntityCategoryProxy.php' (include_path='C:\xampp\htdocs\CoChces\application/../library;C:\xampp\htdocs\CoChces\library;.;C:\xampp\php\PEAR') in C:\xampp\htdocs\CoChces\library\Doctrine\ORM\Proxy\ProxyFactory.php on line 85
但如果我在购买中评论这一行:
/**
*
* @var User
* @ManyToOne(targetEntity="User")
* @JoinColumns({
* @JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
Everithing 工作得很好。所以@ManyToOne注释肯定存在某种问题。有人知道该怎么办吗?也许有一些解决方法?
非常感谢您的回答..
我正在使用 PHP 5.3.8
I basicky followed this http://www.zendcasts.com/one-to-many-with-doctrine-2/2011/03/ tutorial to the step (source codes can be downloaded from there). And everything works just fine, so I got 2 Entities - Purchase and User. If I query User everything is fine, but if I query Purchase, like so:
$entityManager->createQuery('select p from ZC\Entity\Purchase p where p.id = 1')->execute();
I will get an Fatal error:
Fatal error: require() [function.require]: Failed opening required 'C:\xampp\htdocs\CoChces\application/../library/CC/Entity/Proxy\CCEntityCategoryProxy.php' (include_path='C:\xampp\htdocs\CoChces\application/../library;C:\xampp\htdocs\CoChces\library;.;C:\xampp\php\PEAR') in C:\xampp\htdocs\CoChces\library\Doctrine\ORM\Proxy\ProxyFactory.php on line 85
But if i comment this lines in Purchase:
/**
*
* @var User
* @ManyToOne(targetEntity="User")
* @JoinColumns({
* @JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
Everithing works just fine. So there must be some kind of problem with @ManyToOne annotation. Anyone know what to do with it? Perhaps some workaround?
Thanks a lot for answers..
I'm using PHP 5.3.8
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几件事...
您的注释语法似乎不正确。尝试一下
<前><代码>/**
* @var 用户
* @ManyToOne(targetEntity="用户")
*/
私人$用户;
@JoinColumns
未出现在文档中的任何位置。此外,当您使用默认值时,@JoinColumn
注释是多余的。请参阅http: //www.doctrine-project.org/docs/orm/2.1/en/reference/association-mapping.html#many-to-one-unidirect您的 DQL 查询引用
ZC
命名空间根,但错误消息显示CC
。哪个是正确的?Couple of things...
Your annotation syntax doesn't appear to be correct. Try
@JoinColumns
doesn't appear anywhere in the documentation. Also, the@JoinColumn
annotation is redundant as you are using the default values. See http://www.doctrine-project.org/docs/orm/2.1/en/reference/association-mapping.html#many-to-one-unidirectionalYour DQL query references the
ZC
namespace root but the error message saysCC
. Which is correct?