1

I have a few models which need to be linked together during a workflow on my webapp and I'm having trouble thinking of a nice abstraction for the api.

They are represented as individual constructs on the backend with their own CRUD methods that can be hit individually, however when the front-end saves a model it has to pull (to visualize) and push (to save) all the parts which need to be separately saved and linked together through foreign keys across tables.

I have 3 ideas for doing this so far:

  1. Batch Http requests to individual creation endpoints. (If all of the individual endpoints work I can be relatively sure that the linkages exist)
  2. Wrap the operations in a higher level nested transaction that calls the individual cruds and rollsback if any failed. Requires making linker functions that intake pairs of objects.
  3. Have a container object for the frontend that contains all the parts on the backend and define a .toBackendRep() method on it that maps those fields to their database tables

I don't want to lose data, I want to actually test this thing, and assembling all of the parts right before serving them back to the user seems messy. If anyone has opinions on what works I'd be grateful.

1

If the separate models are linked together on the db, I would consider the aggregate root approach.

In this case you would only download and save the root model. all the others would be child objects in that class which you cant save seperately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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