开发者

STI or Polymorphic approach with this design?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜