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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:46:37+00:00 2026-06-13T22:46:37+00:00

Normally to create/alter a table in database I use migrations (manually run rake db:migrate

  • 0

Normally to create/alter a table in database I use migrations (manually run rake db:migrate) and then in my code I use ActiveRecord. This is very cool as I don’t have to worry about representation of the data in db and about a specific kind of db (sqlserver, pg or other).

But now a customer wants to be able to create “things” on-fly himself like, say, he starts selling computers, so he wants to an interface where he can dynamically create an object “computer” with properties like “Name, RAM, HD, …”. It seems to be quite natural to create a separate table in db with all these fields. But how can I do that in RoR and keep all these nice things about ActiveRecord?

Please suggest.

  • 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-13T22:46:38+00:00Added an answer on June 13, 2026 at 10:46 pm

    The usual way is to do exactly the opposite:

    • Have a table for object types
    • Have a table for field names for each object type
    • Have a very big table with all the custom attributes for each object of any type

    This is called EAV (Entity-attribute-value model, see http://en.wikipedia.org/wiki/Entity-attribute-value_model). And it scales pretty bad.

    Alternatively, you can use a store text column instead of the big EAV table (see http://api.rubyonrails.org/classes/ActiveRecord/Store.html) so you don’t have to make those difficult attribute retrievals, typical of EAV. You still need to store somewhere the “object types” definitions, so the expected fields etc are available when building forms and tables.

    The problem with this approach is that you are not able to query (where/join/select) on those attributes because they are not columns. There are a number of solutions to that:

    • Don’t do filtering on those attributes (meh…)
    • Have an external search server that’s able to do faceted search
    • (as @Amar correctly says) Use a document database
    • Use postgreSQL and use hstore instead of a simple serialized column.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let suppose we've database table my_code Input I'll create connection to this database table
i have write this block of code in jquery to create three element after
Normally in SSRS reporting, to create a report we define a datasource, then we
The table arg_rec contains 800K rows on my test machine, normally this table will
I normally create apps for the iPad, but I decided to make one for
Normally if you create a Stream object, the head will be eagerly evaluated: scala>
If you create a Filter object that contains criteria for Linq that normally goes
A class is composed normally of member variables & methods. When we create instance
I have created menu with tabs and under tabs I use <button> s. Normally
Normally, you don't actually edit a file in vim. If you run vim foo

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.