Ruby on rails 评论;“铁路之路”关于表关系和rails方式或解决问题
我希望在我的应用实体中实现一个站点范围的评论/消息功能。这将使人们能够对以下模块进行评论Ruby on rails 评论;“铁路之路”关于表关系和rails方式或解决问题,ruby-on-rails,ruby,ruby-on-rails-4,comments,table-relationships,Ruby On Rails,Ruby,Ruby On Rails 4,Comments,Table Relationships,我希望在我的应用实体中实现一个站点范围的评论/消息功能。这将使人们能够对以下模块进行评论 Newsletters Reports Tasks and user to user (messaging) 我的计划是创建一个名为“entity_id”的外键,它与任何一个表都不相关。相反,它与commentEntity_id结合在一起,commentEntity_id是可以对其进行注释的所有表的列表 例如: 因此,注释将有一个CommentEntity,它指向报告,还有一个entity_id,在本例
Newsletters
Reports
Tasks
and user to user (messaging)
我的计划是创建一个名为“entity_id”的外键,它与任何一个表都不相关。相反,它与commentEntity_id结合在一起,commentEntity_id是可以对其进行注释的所有表的列表
例如:
因此,注释将有一个CommentEntity,它指向报告,还有一个entity_id,在本例中,它是报告表的id
我构建它的方法是制作以下表格
Comment #along with user_id and a comment body:string, this will also have a commentEntity_id and a entity_id
CommentInvolvement # simply everyone involved (either by commenting on the entity, or in the case of user to user, **being** the entity)
CommentEntity # This is the join between the comment and the place
it's put.
这将是我在PHP项目中的解决方案,尽管我知道Rails需要不同的思维方式,所以我想了解社区对这个问题的想法,以及这是否是解决这个问题的最佳方式
谢谢是的,Rails通过 comment.rb
belongs_to :commentable, polymorphic: true
其他型号
has_many :comments, as: :commentable
注意:您必须在comments表
commentable\u id
(Integer)和commentable\u type
(String)中添加两列。您还应该查看有关多态关联的详细信息
d