dongxun1142 2015-07-02 10:26
浏览 69
已采纳

延迟加载实体的Doctrine Repository机制如何工作?

So, I want to understand how the Doctrine Repository mechanism works.

For my entities I use annotations, so the resulting object is built somewhere during the execution of the script.

I'd like to unserstand which are the possibile ways of implementing the lazy loading of entities from another entity.

In concrete, using Doctrine, I have the ability to fetch information of related object (from the Symfony book). This fetching is done in a lazy way: only if I call the method to get the information about the Entity it is loaded from the database querying it.

Now, I'd like to better understand this mechanism: how an entity can implement repository methods? How can I reproduce this mechanism to implement it in other context similar to the one of a database data retrieval?

As the resulting object is really big, is there someone who can put me on the right way? Which classes should have I read to understand the mechanism? Are there any articles/posts that better explain how this mechanism is implemented? Are there better (or simply simpler) ways of implementing it?

  • 写回答

3条回答 默认 最新

  • dtw52353 2015-07-17 10:42
    关注

    I think the best description of the lazy loading can be found in Doctrine developer articles. http://www.giorgiosironi.com/2009/07/lazy-loading-of-objects-from-database.html http://www.giorgiosironi.com/2009/08/doctrine-2-now-has-lazy-loading.html

    The main idea is to insert into Product's category list a set of objectes that are subclasses of Category. These and called "proxy objects" and created "on the fly" when Product is retrieved from database. These proxy objects have the same interface as Category object, but add functionality of loading actual Category items from database when needed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)