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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:52:11+00:00 2026-05-15T09:52:11+00:00

Given you have to implement a news feed like the one seen in social

  • 0

Given you have to implement a news feed like the one seen in social networks, ex facebook.
Currently I’m using a News class which has a polymorphic assocation which can be of any kind like Image, Comment, Friendship, GroupMembership, etc. Whenever an Object is created, as News is created too. It’s working fine with AR(ActiveRecords) but I get into trouble when I’d switch to DM(DataMapper) or Sequel as both don’t natevily support polymorphic associations and discourage it’s usage.

One workaround would be to use a big SQL clause with lot’s of UNIONs to merge all the different tables which should be considered as news. But this has some drawbacks, escpecially performance would be terrible.

So I wonder how to solve without polymorphic associations while still getting good performance and no other drawbacks, like having the possibility of adding meta data to a news?

  • 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-15T09:52:11+00:00Added an answer on May 15, 2026 at 9:52 am

    Disclaimer: I’m the lead developer of Sequel.

    The best way to go about it usually depends on what types of things you want to do with the data. One way to go about it is to have foreign key columns for all possible relationships:

    news:
      id
      ... (Other columns)
      image_id
      comment_id
      friendship_id
      group_membership_id
    

    There is really no performance difference in doing things this way versus having a generic foreign key and storing a class name. For lazy loading, you just pick the one foreign key field that’s not nil/NULL, and choose the appropriate association to load. For query-per-table eager loading, you just load all associations at once. This also is more flexible in that you can eagerly load using JOINs, which isn’t possible with the polymorphic approach. Plus, you get the benefit of real referential integrity.

    The one downside is that if you want to add more association types in the future, you need to add foreign keys to the table.

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

Sidebar

Related Questions

I have to implement a logic whereby given a child class, I need to
I have to implement a rule that only one 'group' with a given ID
I would like to implement offline reading for a news application I have been
I am learning Java and have been given these options: How can you implement
Given: I have an interface. I have only class that implements that interface. Question:
Given I have table with some data... I have a query which is used
Given I have a class with two constructors: public class TestClass { ObjectOne o1;
Given I have a controller class as such: public class ResourceController : AuthorizedController {
I have to implement a webservice client to a given WSDL file. I used
I have a Django application in which I need to implement a simple trending/ranking

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.