How should changes to MVC objects be propagated?

泪湿孤枕 提交于 2020-01-16 04:45:11

问题


This is a follow-up to a previous question: Should sub-objects be fetched in the Model or the Model Mapper?

Let's say a User can have one or more PhoneNumber objects. According to the answer in the above question, these sub-objects will be fetched upon instantiation of the User. If I were to delete a PhoneNumber from the User's phoneNumbers property (an array of PhoneNumbers), or modify one of the PhoneNumber objects, where should this change be propagated?

Should I manually delete/update the sub-objects in the database, or should the User do that automatically on save? Thank you,


回答1:


Let's see If I got it the right way.

The user is logged and it's on his profile page. On this page the user clicks a link "delete this phone number".

On the page where the action is performed it will executed DELETE FROM phones ETC.

Now after this is performed when you will load the User, the constructor will load the phonenumber etc and considering you performed the DELETE sql early the current user object will not have, of course, the just deleted phonenumber.

This is at least what happens in my MVC framework.



来源:https://stackoverflow.com/questions/6237991/how-should-changes-to-mvc-objects-be-propagated

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