1

我期待在我的應用程序實體中實現全站評論/留言功能。這將使人們對以下模塊評論「軌道方式」 - 關於表格關係和軌道方式或解決問題

Newsletters 
Reports 
Tasks 
and user to user (messaging) 

我的計劃是使外鍵被稱爲「ENTITY_ID」不涉及任何單個表發表評論。相反,它與commentEntity_id結合在一起,它是可以評論的所有表的列表。

例子:

所以評論必須指向報告也是一個ENTITY_ID,在這種情況下,是報告表的ID的CommentEntity。

我將建立這個問題的方法是使下表

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的,需要不同的思維方式,所以我希望得到社區對這個問題的看法,而且這是解決問題的最好方法嗎?

感謝

回答

3

是,Rails的支持通過Polymorphic associations

comment.rb這種方法

belongs_to :commentable, polymorphic: true 

其他車型

has_many :comments, as: :commentable 

注意:您要在註釋添加兩列表commentable_id(Integer)和commentable_type(字符串)

+0

啊,當然。我記得有關這個的閱讀!謝謝。 –