开发者

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

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开发者_C百科 called getBooks that takes a Patron ID

What would you recommend? Thank you,


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜