I have a Hotel
entity which can have many address
and many image
objects i.e. they are one2many related with the hotel.
The question arises while fetching and saving the linked resource.
Fetching
- I load the resource which is Hotel here which has the
ids
array of the address as well as image, these address contains the unique ids for each related resource, after hotel is fetched the next request is made to fetch address and images either one after another or in parallel (parallel may be better because they are not related). The downside is that there are three network requests(one for hotel and then addresses and images) and has the downside of showing the partial information such as all address not fully fetched in case server is down. - When the hotel resource is requested the application on server does all the work and with help of database joins all the information is sent in one go probably taking more time. Now, in this case the resource has an array of actual address and image objects.
Saving
- In case of new resource all the information is passed to the server at one go i.e. resource with the array of address and thumbnail links. In this case linked resource are saved first i.e. address is saved first then its id is linked to the resource and then resource is saved. If the address is failed to save we rollback whole action and consider it failed and ask client to try again.
- For update I have to give some more thought, maybe design the UI such that only one linked resource can be updated at a time.
I would like to hear if there are any better approach or which of my approach is better and why?