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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:13:26+00:00 2026-06-01T20:13:26+00:00

Is it ok to have only one model that can hold many different types

  • 0

Is it ok to have only one model that can hold many different types of subscriptions?

For example, lets say you can subscribe to comments, users, forum threads and news articles inside of an application. They all have different types of columns though. This how it would look with the associations setup.

Users
 attr_accessible :name, :role
 has_many :subscriptions
 has_many :comments, :threads, :articles, :through => :subscriptions

Comments
 :content, :rating, :number
 has_many :subscriptions
 has_many :subscribers, :through => :subscriptions, :class_name => 'User'  

Threads
 :title, :type, :main_category
 has_many :subscriptions
 has_many :subscribers, :through => :subscriptions, :class_name => 'User'

Articles
 :news_title, :importance
 has_many :subscriptions
 has_many :subscribers, :through => :subscriptions, :class_name => 'User'


Subscription
 :content, :rating, :number, :name, :role, :title, :type, :main_category, 
 :news_title, :importance, :user_id, :comment_id, :thread_id, :article_id 

 belongs_to :user, :comment, :thread, :article

Basically with one subscription model a user can choose to subscribe to a comment, thread or article and even all three at once. Can it work this way? Where one model can hold all different types of subscriptions, especially when you want to compare attributes to do certain things like articles for certain users?

  • 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-01T20:13:27+00:00Added an answer on June 1, 2026 at 8:13 pm

    You could try to do this more universal with polymorphic associations:
    http://guides.rubyonrails.org/association_basics.html#polymorphic-associations

    For example,

    Subscription
      :subscriber_id, :subscribable_id, :subscribable_type
    
      belongs_to :subscriber, :class_name => "User"
      belongs_to :subscribable, :polymorphic => true
    
    User
      has_many :subscriptions
    
    Comment
      has_many :subscriptions, :as => :subscribable
    
    Article
      has_many :subscriptions, :as => :subscribable
    

    and then create new subscription like this

    user.subscriptions.create(:subscribable => article)
    

    and use it like this (if you actually care about type)

    user.subscriptions.where(:subscribable_type => "Article").each do |subscription|
       article = subscription.subscribable
       # do stuff with article
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that ScrollView can have only one Child but in my case I
So in a typical model where you have a parent that can have many
If I have Model.objects.all() I want to get only one object for any content_object=foo,
I have only one class with many instances. Every instance is observer of couple
I have two sites with different SITE_IDs, but I want to have only one
I'm writing a django model that allows my site to have coupons. Coupons can
I am struggling with designing a coreData model where I have only one type
I have many different arrays with dictionaries of hotels in a data model class.
I have a model that for edit/update actions only is logically split into two
Say I have django model that looks something like this: class Order(models.Model): number =

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.