Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 583437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:47:33+00:00 2026-05-13T14:47:33+00:00

I have several models whose records AND associations can have two states that must

  • 0

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:

Draft version of database table

Bernie

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:47:34+00:00Added an answer on May 13, 2026 at 2:47 pm

    The catch is that both the final and draft have associations that must be kept in sync

    How can a final version change, ever? Final versions should be immutable.

    Do you mean that someone might draft and submit a document whilst other users are making drafts?

    If so, source control seems applicable. A wiki-approach for merging documents would be useful, or a simple ‘locking’ principle so that two users cannot conflict.

    As for storing a versioned document, if you discount using the file system and want to use a conventional database, there’s two main approaches:

    1. put it all in a single table, with a flag for draft|final, and a flag for the ‘head’ – the most recent final version of each document

    2. three tables: a table of the ‘heads’, a separate table of drafts and a third table with the historic final versions

    The advantage of one approach over the other will be performance and distribution if the system gets really big.

    But if the system is small, I’d advocate the first approach – a single table – possibly with the finesse of three ‘views’ so as to make migration to the more complicated three-table approach less painful in version 2.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several models that belong_to :status . Statuses are: Active Hidden Banned I
If you have several view models on one page, how do you ensure that
I have several small classes that are in a single file in /app/models, similar
I have several models that includes nested classes and lists. Many of the class
I have several models with fields that are integers. I also have hashes that
I have several models that are related to one another through a HABTM relationship.
In Silverlight for Windows Phone I have several view models that are disposable and
I have several models that save log data to my database. I also have
In my project, I have several models that use a number of scopes that
I have several doctrine models that have relationships to other models. Let's call those

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.