Should sub-objects be fetched in the Model or the Model Mapper?

独自空忆成欢 提交于 2019-12-13 03:59:23

问题


This is a follow-up to my previous question: Should dependent rows be fetched in the Model or the Controller?.

Let's say that a Patron can check out Books. If, given a Patron object, where and how should the Books they have checked out be fetched?

Here are some possibilities I've considered:

  • In the Patron Model, add a getBooks method
  • When a Patron is instantiated, automatically get its books and store it as the books property
  • Create a method in the PatronMapper called getBooks that takes a Patron ID

What would you recommend? Thank you,


回答1:


I suggest you to go with:

When a Patron is instantiated, automatically get its books and store it as the books property

This way you don't have to manually worry about it



来源:https://stackoverflow.com/questions/6237817/should-sub-objects-be-fetched-in-the-model-or-the-model-mapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!