Zend 框架,原则 2 @ManyToOne

发布于 2024-12-09 06:14:39 字数 1087 浏览 0 评论 0原文

我基本上遵循了这个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 技术交流群。

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

发布评论

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

评论(1

有木有妳兜一样 2024-12-16 06:14:39

有几件事...

  1. 您的注释语法似乎不正确。尝试一下

    <前><代码>/**
    * @var 用户
    * @ManyToOne(targetEntity="用户")
    */
    私人$用户;

    @JoinColumns 未出现在文档中的任何位置。此外,当您使用默认值时,@JoinColumn 注释是多余的。请参阅http: //www.doctrine-project.org/docs/orm/2.1/en/reference/association-mapping.html#many-to-one-unidirect

  2. Direction

    您的 DQL 查询引用ZC 命名空间根,但错误消息显示 CC。哪个是正确的?

Couple of things...

  1. Your annotation syntax doesn't appear to be correct. Try

    /**
     * @var User
     * @ManyToOne(targetEntity="User")
     */
    private $user;
    

    @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-unidirectional

  2. Your DQL query references the ZC namespace root but the error message says CC. Which is correct?

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