0

Also stems from this question : Rails naming convention for join table

I want to create more than one join tables which link 2 models together with different relation. Let's say I have models User and Post. The first relationship table relate users with their created posts, and the another one relate users with their liked posts. How should I named these tables ? Or am I doing anything wrong with database design ?

Community
  • 1
  • 1
CatFly
  • 440
  • 1
  • 3
  • 11
  • Why would you need separate relationship table for users -> Posts ? Don't you have a `User has_many :posts` and `Post belongs_to :user`? in which case you don't need a separate table, just add column `user_id` in `posts` table – Kkulikovskis Jun 07 '16 at 11:06
  • What if i have more relationship ? like users could report posts or something. – CatFly Jun 07 '16 at 13:52
  • then you have another relationship table. Or better yet- if there are a lot of relationship types between posts and users then make a STI with a table `user_post_relationships` or smth that has columns `"user_id", "post_id", "relationship_type"` which would be for example `"Reported"` and `"Liked"` – Kkulikovskis Jun 08 '16 at 08:06

0 Answers0