Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a "complete later" functonality with non-null fields?

Environment
Spring/hibernate/MySQL web application

Problem
I have a multi-step form which should be savable at every step for completing later. But incomplete steps may contain fields that are required for the model, making it not possible to save the model.

What I have tried or thought about trying

  1. Making fields nullable.
  2. Using a temporary table to save incomplete forms

But..
Solution 1 disrupts database design, and solution 2 will bloat my code with fragments to convert between the temporary model and the permanent one, and this will get ugly if I add the ability to edit the form after saving it.

How to implement the complete later feature in a way that is seamless and elegant?

like image 760
Isaac Avatar asked Dec 20 '12 06:12

Isaac


2 Answers

Another option is to have a boolean column in your database table complete_edit . and for those columns that are not entered in first place during save, either store default value or a string like "NOT_COMPLETE" and set complete_edit column as false. Only on submit this column should be true.

like image 64
Subin Sebastian Avatar answered Oct 05 '22 11:10

Subin Sebastian


FWIW, I am strongly against temporary table to save incomplete form. We have a similar set up in our current application (to prepare invoices in multiple steps that could span different user sessions) that's posing maintainability issues and incoherent modifications to the temporary and permanent tables.

We are moving towards a single table approach with discriminator status column that would classify these in-progress-invoices such that they are not picked by the subsequent workflow steps until the status is flipped.

like image 35
Vikdor Avatar answered Oct 05 '22 12:10

Vikdor