16
Beyond Foreign Keys (lackofimagination.org)
submitted 7 months ago* (last edited 7 months ago) by Aijan@programming.dev to c/programming@programming.dev

In a relational database, foreign keys are normally used to associate records stored in different tables, but wouldn’t it be nice to define relationships dynamically without having to add extra columns or tables? And while we’re at it, how about having sparse relationships by associating a record directly with any other record like “post X was last edited by user #123” or “post X was flagged for review by user #456” (who happens to be a moderator)?

you are viewing a single comment's thread
view the rest of the comments
[-] Kache@lemm.ee 8 points 7 months ago

So... a polymorphic many-to-many join table?

[-] Aijan@programming.dev 2 points 7 months ago

Yes, that's correct. Here's how an entry in the join table looks like:

{
  "id": 6,
  "sourceComp": "user",
  "sourceId": 2,
  "targetComp": "post",
  "targetId": 3,
  "type": "author",
  "createdAt": "2024-03-28T13:28:59.175Z",
  "updatedAt": "2024-03-28T13:28:59.175Z"
}
[-] jkrtn@lemmy.ml 3 points 7 months ago

Don't you want a graph database at this point?

[-] Aijan@programming.dev 3 points 7 months ago* (last edited 7 months ago)

That idea crossed my mind too, but you can’t really use the full capabilities of SQL in graph databases, and that’s a deal breaker for me.

load more comments (1 replies)
load more comments (3 replies)
load more comments (3 replies)
this post was submitted on 11 Apr 2024
16 points (100.0% liked)

Programming

17424 readers
44 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS