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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:15:59+00:00 2026-06-15T23:15:59+00:00

I want to present my case, and know whether or not I should use

  • 0

I want to present my case, and know whether or not I should use STI solution.
I am creating a message-board website and so far I have couple of Models: User, Topic, Post..
to make it clear: Post is like a comment for a Topic. Topic has title and content. Post has only has content.

Now, the User has the option to Like/Dislike a Post or a Topic.
I thought about three options:

  1. Topic and Post don’t have a connection (each Model has “num_of_likes”, “num_of_dislikes”)
  2. Topic inherit Post.
  3. Topic and Post inherit from a Base Model which can be called LikeableObj for example.

Which of those three options is the most suitable for my needs?
Is there a fourth option I didn’t think about?
What if I’d like in the future to have a third Model which can be Liked?

  • 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-15T23:16:00+00:00Added an answer on June 15, 2026 at 11:16 pm

    I assume you’ll want to keep track of whether a user has liked a certain post or topic, so I would make a join model for likes that connects a user to either a post or topic.

    class Like < ActiveRecord::Base
      belongs_to :user
      belongs_to :liked_obj, polymorphic:true, counter_cache:true
    end
    

    Since the liked_obj is polymorphic, it can be a post or a topic. You can then put has_many :likes on those models and a column likes_count, which will be updated automatically as a counter cache.

    If you have any code that deals with likes that is common between Post and Topic, put it in a module Likeable and include it in both classes.

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

Sidebar

Related Questions

I want to know whether a particular key is present in a HashMap, so
I want to know whether the current time is present between the start time
I want test whether a string is present within any of the list values
I want to present an iPad game which is only playable in portrait mode
I want to present a modalViewController with a small frame and at the center
I want to present an alert window with no button on it, that means
In my application I want to present a list of choices for a user
I have a UINavigationController/UITableView and I want to present a UIView over top of
I create some KML files in my project and I want to present on
I have two screens on my app that I want to present to users,

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.