2

There's a complex model which represented by complex JSON with multiple fields and nested objects. Recently we have discussed in which way indicate to the backend that the object needs to be saved as new. There're two many proposals:

  • remove id field from the model to indicate backend that new object needs to be created
  • explicitly tell by creating new nested object saveAsNew with fields which need to be changed

1 Answer 1

3

Option 1 lets you reuse existing facilities (if this is how you've inserted objects so far), which are already tested and maintained.
Moreover, it lets you to have saved copies of the object for your reference (assuming the old record is being saved, or "harvested" after some time).

  • It's simple, already implemented and tested which should be appreciated.
  • It's stupid and inefficient, especially if the objects are large and the updates require only a handful of fields which are "small".

Option 2 requires you to employ infrastructure upgrade (from reading your thread), which needs to be engineered. It can help you to achieve fine-grained update for objects and thus be efficient for the case I mentioned above.
Yet, you need to reserve saveAsNew field, its' fields should be checked for user-errors depending on the environment you operate in and it may require you to create a specialized logic for-each data object (again, depending on your requirements which you didn't elaborate).
If the only way you communicate with your back-end is through this JSON object, you may have no-choice but to send this sort of data inside it as you already suggested.

I would advise you to take this considerations in your final choice;
If you have the infrastructure already set-up for option 1 and you don't deal predominantly with the case I mentioned (and even if so, you profiled it and saw a noticeable difference in fine-grained updates (taking into consideration the validation checks too in your tests)), I would go with option 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.