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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:27:35+00:00 2026-05-20T08:27:35+00:00

In my rails 3 model, I have two classes: Product, Service. I want both

  • 0

In my rails 3 model, I have two classes: Product, Service. I want both to be of type InventoryItem because I have another model called Store and Store has_many :InventoryItems

This is what I’m trying to get to, but I’m not sure how to model this in my InventoryItem model and my Product and Service models. Should InventoryItem just be a parent class that Product and Service inherit from, or should InventoryItem be modeled as a class abstract of which Product and Service extend from.

Thanks in advance for the advice!

  • 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-20T08:27:35+00:00Added an answer on May 20, 2026 at 8:27 am

    I’d use neither, and follow what Mörre suggested to have InventoryItem be a join model:

    class Store
      has_many :inventory_items
      has_many :products, :services, :through => :inventory_items
    end
    
    class InventoryItem
      belongs_to :store
      belongs_to :products, :services
    end
    
    class Product
      has_many :inventory_items
      has_many :stores, :through => :inventory_items
    end
    
    class Service
      has_many :inventory_items
      has_many :stores, :through => :inventory_items
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Rails 3.2 models directory, I have a folder foo containing two classes:
In my rails model I have some kind of template system. I want to
I have a rails model where I want to update an attribute by calculating
I have a Ruby on Rails model that has a column called expiration_date .
I have a model in Rails called Recipe. The recipe model contains ingredients. Each
I have a rails model called 'audioclip'. I orginally created a scaffold with a
I have a basic Rails model with two properties, name and code . I
In my rails application I have two models called Kases and Notes. They work
I want a rails model to exclude certain patterns: runs of two or more
Complete rails newbie trying to get started. I have two classes, Ingredient, and Unit.

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.