Hi there, I have several models whose records AND associations can have two states that must be persisted. Final, and Draft.
Here's a little more detail: If the model is "application form" and the user submits a final application form, then I need to store and be able to retrieve that final application form.
If, at a later date, the user wants to modify that 'application form', then they need to edit a draft copy of that final record until he submits a new final version. That is, he cannot edit the previous final application form until he checks the "final" box, at which point the draft becomes the new final version.
The catch is that both the final and draft have associations must be stored with their related records. That is, their related records (e.g. an application has many contact persons) must be stored in a manner that is retrievable from the final and the draft versions without confounding a 'final' contact and a 'draft' contact.
Currently I can think of two ways to solve this problem:
- Use ActsAsAudited and audit only the final records. Querying for the finals whenever I need them. (There's a fork of ActsAsAudited that also tracks associations). Then query the Audit tables for the latest records.
- Use two parallel data table sets: One that keeps the drafts, and another that keeps only the final copies.
I THINK keeping the finals and drafts in the same table might duplicate the purpose of those tables, and render the structure more difficult to follow.
Do you know of any other schema or strategy that would handle the problem more elegantly? Or that would reduce code complexity?
Here's a similar question that ended up using the second option above:
http://stackoverflow.com/questions/629873/draft-version-of-database-table
Bernie