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 8742085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:26:15+00:00 2026-06-13T11:26:15+00:00

there are many ActiveRecord versioning gems available to Rails but most if not all

  • 0

there are many ActiveRecord versioning gems available to Rails but most if not all of them are having trouble being maintained. on top of that, some of them seem to have various foreign key association issues.

I’m in the process of coding a content management system where pages are stored in a tree-like hierarchy and the page fields are stored in a separate table using EAV model.

keeping that in mind, I’m not looking for an all encompassing revisioning gem because I honestly don’t think I’ll find one. what I am looking for is some advice on how to handle this as a custom implementation. should I have a separate table for storing revisions and referring to a revision number in my EAV table? I foresee that this may lead to some complex validation problems though. I currently have a problem finding a clean way to validate a regular EAV table anyway so if anyone can comment on this it would be very much appreciated as well.

I hope this question is written well enough to SO standards. if you need any additional information, please do not hesitate to ask and I will try to help you help me. 🙂

  • 1 1 Answer
  • 0 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-06-13T11:26:16+00:00Added an answer on June 13, 2026 at 11:26 am

    I currently have a problem finding a clean way to validate a regular
    EAV table anyway so if anyone can comment on this it would be very
    much appreciated as well.

    There isn’t a clean way to either validate or constrain an EAV table. That’s why DBAs call it an anti-pattern. (EAV starts on slide 16.) Bill doesn’t talk about version, so I will.

    Versioning looks simple, but it’s not. To version a row, you can add a column. It doesn’t really matter much whether it’s a version number or a timestamp.

    create table test (
      test_id integer not null,
      attr_ts timestamp not null default current_timestamp,
      attr_name varchar(35) not null,
      attr_value varchar(35) not null,
      primary key (test_id, attr_ts, attr_name)
    );
    
    insert into test (test_id, attr_name, attr_value) values
    (1, 'emp_id', 1),
    (1, 'emp_name', 'Alomar, Anton');
    
    select * from test;
    
    test_id  attr_ts                      attr_name   attr_value
    --
    1        2012-10-28 21:00:59.688436   emp_id      1
    1        2012-10-28 21:00:59.688436   emp_name    Alomar, Anton
    

    Although it might not look like it on output, all those attribute values are varchar(35). There’s no simple way for the dbms to prevent someone from entering ‘wibble’ as an emp_id. If you need type checking, you have to do it in application code. (And you have to keep sleep-deprived DBAs from using the command-line and GUI interfaces the dbms provides.)

    With a normalized table, of course, you’d just declare emp_id to be of type integer.

    With versioning, updating Anton’s name becomes an insert.

    insert into test (test_id, attr_name, attr_value) values
    (1, 'emp_name', 'Alomar, Antonio');
    

    With versioning, selection is mildly complicated. You can use a view instead of a common table expression.

    with current_values as (
      select test_id, attr_name, max(attr_ts) cur_ver_ts
      from test
      -- You'll probably need an index on this pair of columns to get good performance.
      group by test_id, attr_name
    )
    select t.test_id, t.attr_name, t.attr_value
    from test t
    inner join current_values c 
            on c.test_id = t.test_id
           and c.attr_name = t.attr_name
           and c.cur_ver_ts = t.attr_ts
    
    test_id   attr_name   attr_value
    --
    1         emp_id      1
    1         emp_name    Alomar, Antonio
    

    A normalized table of 1 million rows and 8 non-nullable columns has a million rows. A similar EAV table has 8 million rows. A versioned EAV table has 8 million rows, plus a row for every change to every value and every attribute name.

    Storing a version number, and joining to a second table that contains the current values doesn’t gain much, if anything at all. Every (traditional) insert would require inserts into two tables. What would be one row of 8 columns becomes 16 rows (8 in each of two tables.).

    Selection is a little simpler, requiring only a join.

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

Sidebar

Related Questions

I am writing an application where many (but not all) ActiveRecord models have a
There have been many questions about this, but none of them seem to help.
There are many errors here in SO, but this scenario I think its different.
There are many similar questions, but I didn't find one that gets straight to
I have a Rails app with users, suggestions and searches. There is a many-to-many
Are there any shortcuts in Rails' ActiveRecord that enables you to search by value
Like on StackOverflow, there is a question and that question has many answers. But
There were many questions about C++ template classes which contain static member variables, as
There are many similar questions, however they don't answer the problem of a url
Background I'm designing a Rails app to record research data. Most of it can

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.