FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
The Likes Table Problem: Why We Went Polymorphic.
How-ToSystems

The Likes Table Problem: Why We Went Polymorphic.

via Dev.toSaurav Dhakal1mo ago

A few days ago, I was working on adding a Community section to an application. The idea was simple, users should be able to: Create posts Leave comments Like posts Like comments We also had a separate News section. The new requirement was users should be able to like news articles as well. Building model for posts and comments was pretty straight forward. The real challenge was to model the likes table. The Problem: How Do We Store Likes? We’re using PostgreSQL, so enforcing relationships with foreign keys is easy and clean. If only one thing could be liked (say, News), the schema would be simple, we would have a news_like table which could look something like this: user_id news_id timestamp (foreign key) (foreign key) But we didn’t have one entity. We had three. posts , comments and news . We had to decide: Do we create three separate like tables? Or do we design one flexible solution? Option 1: Three Separate Tables We could create three tables: post_likes , comment_likes and news_li

Continue reading on Dev.to

Opens in a new tab

Read Full Article
22 views

Related Articles

How-To

How I Stay Consistent While Learning Coding

Medium Programming • 17h ago

T-Mobile Business Promo Codes and Deals
How-To

T-Mobile Business Promo Codes and Deals

Wired • 17h ago

150 million users later, Roblox competitor Rec Room is shutting down
How-To

150 million users later, Roblox competitor Rec Room is shutting down

The Verge • 21h ago

Here are our favorite spring cleaning deals from Amazon’s Big Spring Sale
How-To

Here are our favorite spring cleaning deals from Amazon’s Big Spring Sale

The Verge • 22h ago

What we’re looking for in Startup Battlefield 2026 and how to put your best application forward
How-To

What we’re looking for in Startup Battlefield 2026 and how to put your best application forward

TechCrunch • 1d ago

Discover More Articles