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

  • Home
  • SEARCH
  • 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 4062204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:34:10+00:00 2026-05-20T15:34:10+00:00

I have a situation that involves Companies, Projects, and Employees who write Reports on

  • 0

I have a situation that involves Companies, Projects, and Employees who write Reports on Projects.

A Company owns many projects, many reports, and many employees.
One report is written by one employee for one of the company’s projects.

Companies each want different things in a report. Let’s say one company wants to know about project performance and speed, while another wants to know about cost-effectiveness. There are 5-15 criteria, set differently by each company, which ALL apply to all of that company’s project reports.

I was thinking about different ways to do this, but my current stalemate is this:

  • To company table, add text field criteria, which contains an array of the criteria desired in order.
  • In the report table, have a company_id and columns criterion1, criterion2, etc.

I am completely aware that this is typically considered horrible database design – inelegant and inflexible. So, I need your help! How can I build this better?


Conclusion

I decided to go with the serialized option in my case, for these reasons:

  1. My requirements for the criteria are simple – no searching or sorting will be required of the reports once they are submitted by each employee.
  2. I wanted to minimize database load – where these are going to be implemented, there is already a large page with overhead.
  3. I want to avoid complicating my database structure for what I believe is a relatively simple need.
  4. CouchDB and Mongo are not currently in my repertoire so I’ll save them for a more needy day.
  • 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-05-20T15:34:10+00:00Added an answer on May 20, 2026 at 3:34 pm

    This would be a great opportunity to use NoSQL! Seems like the textbook use-case to me. So head over to CouchDB or Mongo and start hacking.

    With conventional DBs you are slightly caught in the problem of how much to normalize your data:

    1. A sort of “good” way (meaning very normalized) would look something like this:

      class Company < AR::Base
        has_many :reports
        has_many :criteria
      end
      
      class Report < AR::Base
        belongs_to :company
        has_many :criteria_values
        has_many :criteria, :through => :criteria_values
      
      end
      
      class Criteria < AR::Base # should be Criterion but whatever
        belongs_to :company
        has_many :criteria_values
        # one attribute 'name' (or 'type' and you can mess with STI)
      end
      
      class CriteriaValues < AR::Base
        belongs_to :report
        belongs_to :criteria
        # one attribute 'value'
      end
      

      This makes something very simple and fast in NoSQL a triple or quadruple join in SQL and you have many models that pretty much do nothing.

    2. Another way is to denormalize:

      class Company < AR::Base
        has_many :reports
        serialize :criteria
      end
      
      class Report < AR::Base
        belongs_to :company
        serialize :criteria_values
      
        def criteria
          self.company.criteria
        end
        # custom code here to validate that criteria_values correspond to criteria etc.
      end
      

      Related to that is the rather clever way of serializing at least the criteria (and maybe values if they were all boolean) is using bit fields. This basically gives you more or less easy migrations (hard to delete and modify, but easy to add) and search-ability without any overhead.

      A good plugin that implements this is Flag Shih Tzu which I’ve used on a few projects and could recommend.

    3. Variable columns (eg. crit1, crit2, etc.).

      I’d strongly advise against it. You don’t get much benefit (it’s still not very searchable since you don’t know in which column your info is) and it leads to maintainability nightmares. Imagine your db gets to a few million records and suddenly someone needs 16 criteria. What could have been a complete no-issue is suddenly a migration that adds a completely useless field to millions of records.

      Another problem is that a lot of the ActiveRecord magic doesn’t work with this – you’ll have to figure out what crit1 means by yourself – now if you wan’t to add validations on these fields then that adds a lot of pointless work.

    So to summarize: Have a look at Mongo or CouchDB and if that seems impractical, go ahead and save your stuff serialized. If you need to do complex validation and don’t care too much about DB load then normalize away and take option 1.

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

Sidebar

Related Questions

The situation: I have a pieceofcrapuous laptop. One of the things that make it
I have a situation that has been partially covered by other answers at SO,
Currently in our enterprise we have a situation that i think it's not very
I've been working on optimizing a query and have ran into a situation that's
I have a situation where I have two entities that share a primary key
I have a situation where I'm starting a number of objects that, when they
Situation: I have a simple XML document that contains image information. I need to
I have the following situation: There is a tool that gets an XSLT from
I have the following situation: I have a certain function that runs a loop
Here is my situation: I have an application that use a configuration file. The

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.