懒惰加载属性没有加载在Doctrine 2.0中 [英] Lazy-loading properties not loading in Doctrine 2.0

查看:91
本文介绍了懒惰加载属性没有加载在Doctrine 2.0中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP和Doctrine 2.0。所有实体都可以正常工作,但下面详细描述的实体关系除外(或其他实体在我没有注意到的情况下失败)。






考虑以下实体:

  / ** @Entity * / 
class Target {
/ **
* @ManyToOne(targetEntity =k\entity\Source,cascade = {persist})
* @JoinColumn(name =basic_vacancy_id,nullable = false)
* @var \k\entity\Source
* /
$ source;

...
}

/ ** @Entity * /
类来源{

...
}

现在,当我调用 $ target-> getSource ()我得到一个 k\entity\proxy\kentitySourceProxy (这是正确的代理类)的实例。但是,Source的所有属性返回 NULL



我可以做错什么?




我已将 fetch =EAGER属性添加到关系注释,现在一切似乎都很好(除了加载不再懒惰的事实)。什么可能导致Doctrine 2.0的懒惰加载中断?

解决方案

如上所述,我已经添加了=EAGER属性到关系注释,现在一切似乎都很好(除了加载不再懒惰的事实)。



这当然是解决方法,而不是修复实际的错误。除此之外,我还不知道是什么导致我的代码/原则打破。然而,这种解决方法的性能影响似乎是可以忽略的 - 如果甚至出现在这里。


I'm using PHP and Doctrine 2.0. All entities work fine, with the exception of the entity-relation detailed below (or other entities are failing where I'm not noticing it).


Consider the following entities:

/** @Entity */
class Target {
  /**
   * @ManyToOne(targetEntity="k\entity\Source", cascade={"persist"})
   * @JoinColumn(name="basic_vacancy_id", nullable=false)
   * @var \k\entity\Source
   */
  $source;

  ...
}

/** @Entity */
class Source {

  ...
}

Now, when I call $target->getSource() I get an instance of k\entity\proxy\kentitySourceProxy (which is the correct proxy class). However, all the getters for Source's properties return NULL.

What could I be doing wrong?


I've added the fetch="EAGER" attribute to the relational annotation, and now everything seems to go just fine (except for the fact that loading is no longer lazy). What could cause Doctrine 2.0's lazy loading to break?

解决方案

As seen above in my question, I've added the fetch="EAGER" attribute to the relational annotation, and now everything seems to go just fine (except for the fact that loading is no longer lazy).

This is of course a workaround, and no fix of the actual bug. In addition to this, I still don't know what caused my code/Doctrine to break. However, the performance impact of this workaround seems to be negligible - if even present at all.

这篇关于懒惰加载属性没有加载在Doctrine 2.0中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆