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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:12:24+00:00 2026-06-05T03:12:24+00:00

If had had the models Store , Product , User and Price with the

  • 0

If had had the models Store, Product, User and Price with the following associations

class User < ActiveRecord::Base
  has_many :products
  has_many :stores
  has_many :prices
end

class Store < ActiveRecord::Base
  belongs_to :user
  has_many :prices
end

class Product < ActiveRecord::Base
  belongs_to :user
  has_many :prices
end

class Price < ActiveRecord::Base
  belongs_to :user
  belongs_to :product
  belongs_to :store
end

class Estate < ActiveRecord::Base
  belongs_to :user
end

And want to create a Option model that holds the models specific option type with things like, if an Estate has a backyard, swimming pool, tennis court or a price has a deal, discount or buy one get one free. Would this be done by a polymorphic association?
I’m doing this so I don’t have to create a Option model for each model and can just have one model for all new options I want to add. So is this the correct way to go about this?

  • 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-05T03:12:26+00:00Added an answer on June 5, 2026 at 3:12 am

    If you use a polymorphic option model, then the fields would be the same for each class/record an object belongs to. I don’t think this is what you want since a deal doesn’t have a swimming pool and an estate isn’t buy-one-get-one (I wish!).

    I would look into using Rails 3.2 and the ActiveRecord::Store feature. With this, just add a single text column to your model(s) (call it “options”) and then you can define all the options you need.

    class Estate < ActiveRecord::Base
      belongs_to :user
      store :options, accessors: [ :backyard, :pool, :tennis, :butler, :wine_cellar ]
    end
    
    estate = Estate.new
    estate.pool = true
    estate.options[:number_of_sharks] = 3 # Attributes not defined as accessors work too
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

These are my associations: class User has_many :products has_many :prices has_many :businesses has_many :stores
I have two models: User and Store class Store < ActiveRecord::Base belongs_to :user class
With the following Store and Service models, managed with MongoMapper: class Store include MongoMapper::Document
I have two stores, Assessor.store.Question and Assessor.store.Choice , along with their respective Models and
Say I have the following model: class Person(models.Model): street_address = models.CharField(max_length=50, blank=True) suburb =
I just finished creating several models and a had to separately write all of
I was wondering whether anyone had any recommendations regarding populating multiple view models on
Had this working; at one stage. The problem is the following text is now
UPDATE OK, I figured it out. I had to call the following for varieties:
What's the best strategy for storing e-commerce product information (i.e. product price, current price)

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.