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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:11:08+00:00 2026-05-31T19:11:08+00:00

Let’s say customer is adding multiple products to cart. Add car, apartment, tour, some

  • 0

Let’s say customer is adding multiple products to cart.
Add car, apartment, tour, some coupons.
Products belong to categories.
Category has name attribute.
But how to give different attributes to car, apartment, tour, coupon?
I can’t definitely create everything from product model.
So should I create different models for each category and connect through has many ro products model?
Or am I going to wrong direction?
Thanks

  • 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-31T19:11:09+00:00Added an answer on May 31, 2026 at 7:11 pm

    Having a Category for individual product seems to be a good approach here. Since your Category differs according to attributes. What you can do is create One more model, let’s say: MasterCategory which has many Category and Category belongs to MasterCategory, which means for your MasterCategory Cars you’ll have Audi, BMW, Nissan etc etc. categories and then link your products to their respective vendors in a table products_categories which will have product_id, category_id.

    In my opinion, schema could go like this:

    ProductsCategory:
    product_id, category_id
    
    MasterCategory:
    id, name, created_at, updated_at
    
    Category:
    id, master_category_id, parent_id, name, position, name, permalink
    

    For e.g. – A car MasterCategory will look like this:

    #<MasterCategory id: 1, name: "cars", created_at: "2012-02-14 13:03:45", updated_at: "2012-02-14 13:03:45">
    

    and its categories will be:

    [#<Category id: 1, master_category_id: 1, parent_id: nil, position: 0, name: "cars", created_at: "2012-02-14 13:03:45", updated_at: "2012-02-14 13:03:45", permalink: "cars">, #<Category id: 2, master_category_id: 1, parent_id: 1, position: 0, name: "Audi", created_at: "2012-02-14 13:03:45", updated_at: "2012-02-14 13:32:51", permalink: "cars/audi">]
    

    Now you can have two methods parent and children in your Category Model using parent_id attribute to locate and traverse master and sub categories easily. And you can use permalink attribute to easily locate a category which is under another category with one query: Category.find_by_permalink(params[:permalink]) and can display all the products related with this particular category. In future when you’ll scale, I can bet you, you’ll require this position attribute to manage position of your categories to display on your page. And in last master_category_id will give you an ease in life with:

    car = MasterCategory.find(1)
    car.categories.where("parent_id IS NOT NULL")
    

    All the best!! 🙂

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

Sidebar

Related Questions

Let's say there is a graph and some set of functions like: create-node ::
Let's say I have multiple requirements for a password. The first is that the
Let's say I have the string: hello world; some random text; foo; How could
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I've got two tables: one with customer data, one with location data.
Let's say I have some json like this in mongo: {n:5} and a java
Let's say I want to have some kind of a cache that did something
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in

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.