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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:12:13+00:00 2026-05-17T17:12:13+00:00

Been going back and forth on how to architect this. I’m using rails,and started

  • 0

Been going back and forth on how to architect this. I’m using rails,and started with Single-Table-Inheritance, then changed my mind, now I’m not sure.

BusinessHours
business_id, day_of_week, start_time, stop_time

StaffHours
staff_id, day_of_week, start_time, stop_time

Obviously a staff member belongs to a business, however the tables for their hours are identical.

Should I store those in one table and add a field like ‘keeper_id’ which stores the id of the staff or business, and a ‘type’ field that store ‘staff_hours’ or
‘business_hours’ to differentiate the two (a staff member and a business may have the same id, so I need to differentiate)

But then I feel like I’m almost back to STI??

Thoughts?

  • 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-17T17:12:14+00:00Added an answer on May 17, 2026 at 5:12 pm

    Much depends on your application domain. I don’t think we have enough information here to know exactly what the correct approach is in your situation. For instance, if your application is primarily concerned with managing and reporting on employee and business schedules/hours, and reporting on those schedules, it might make sense to have a single ‘hours’ table, and relate to it polymorphically. This might look like:

    class Business < ActiveRecord::Base
      has_many :hours, :as => :scheduleable
    end
    
    class Staff < ActiveRecord::Base
      has_many :hours, :as => :scheduleable
    end
    
    class Hour < ActiveRecord::Base
      belongs_to :scheduleable, :polymorphic => true
    end
    

    Here you can still use STI to fork the different Hour functionality if need be. (Note: use the singular when naming your table model, i.e., BusinessHour, not BusinessHours):

    class BuisnessHour < Hour
      validates :some_business_hour_rule
    end
    

    Etc. The key question with STI is, given what I know about my domain, is it likely I would add many attributes/columns specific to a subclass, such that I would have many null columns in, for instance, a row in the hours table representing a StaffHour object that doesn’t use many of the BusinessHour-specific attributes/columns?

    If so, then maybe STI doesn’t make sense for you. But if from what you know about your application’s concerns, the primary difference between subclasses is programmatic and not data-centric, where there are different validations and business rules to operate on mostly identical data, then STI might be the right solution.

    I’d sit down with the Product owner (whoever that is) and the other engineers on the team (if there are any) and whiteboard it. If you’re a team of one, whiteboard it anyway and think through what your application will do with these models in the future. If you’re familiar with UML, it can be a very useful tool to help you visualize the data model in a form other than code. If not, this might be a good excuse to learn a bit. Decisions like these can have a huge impact on general code stability down the road.

    EDIT:

    Another question to ask yourself is, does a Business-specific rule really belong on an Hour object? It could be that it’s more appropriate to have such operations on the Business model itself, and keep Hour simple, unless you truly can imagine a business or staff-specific operation you would call on the Hour model itself. For example this:

    class Business < ActiveRecord::Base
      def calculate_monthly_cost
        # operates on hours 
      end
    end
    

    makes more sense to me from an OOP/SRP standpoint than this:

    class BusinessHour < Hour
      def calculate_business_cost
        # operates on business or uses business-specific rule 
      end
    end
    

    At least, those are the kinds of questions you need to ask to determine the right approach.

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

Sidebar

Related Questions

For a clean data model, I'm going back and forth on this... Using an
I have been going back and forth between C# and Java for the last
I have been using C# for a while now, and going back to C++
We have been going back and forth a lot around our office lately about
I've been going over and over this in my head, and I can't seem
We've been using Trac for task/defect tracking and things were going well enough, but
I've been testing an application using my machine as a server, and everything's going
I am going back and forth with setting an element to minOccurs=0 and nillable=true
I have been going through this page to install zend framework on my machine
Been going over my predecessor's code and see usage of the request scope frequently.

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.