开发者

STI or Polymorphic approach with this design?

开发者 https://www.devze.com 2023-03-09 01:42 出处:网络
Ive got the following models: User, Video, Event, Photo. These models are separate. On the other hand, I\'ve got these models: Like, Comment, Attend.

Ive got the following models: User, Video, Event, Photo. These models are separate.

On the other hand, I've got these models: Like, Comment, Attend.

Basically:

  1. A user can like and comment on a video, event of photo.
  2. A user can attend an even开发者_StackOverflowt.

Should Like, Comment, Attend follow an STI approach and inherit from another class called Interaction?

Or should I follow a polymorphic approach instead?

If STI, should I be worried that the Interaction model is filling up three times as much from Like, Comment and Attend? Should I be worried that one day this model will be 'overloaded'?

What are your thoughts on this?


I think your case could be solved with polymorphism very well, with 'Likes' being in a polymorphic relationship with Video, Event and Photo. Attend and Event should be separate.

This should help: http://railscasts.com/episodes/154-polymorphic-association

0

精彩评论

暂无评论...
验证码 换一张
取 消