2012-02-08 101 views
0

我有我的應用程序評論模型與許多comment_types沒有遷移的模型。 Rails的

class Comment < ActiveRecord::Base 
    belongs_to :comment_type, :polymorphic => true 
end 

我也有一個公共的質量保證體系。因此,對於每一對我有一個模型

class QA < ActiveRecord::Base 
    has_one :question, :class_name => :comment, :as => :comment_type, :autosave => true 
    has_one :asnwer, :class_name => :comment, :as => :comment_type, :autosave => true 
end 

,這似乎有點過度使用對我來說,有質量保證模式的特殊表。因爲這個表應該只有ID鍵。那麼有沒有更好的解決方案?或者我的架構總共可能有問題?

+0

[ActiveRecord :: Base Without Table]的可能重複(http://stackoverflow.com/questions/937429/activerecordbase-without-table) – Ximik 2012-02-08 20:01:27

+0

好像我找到了解決方案。非常遺憾。 – Ximik 2012-02-08 20:02:04

回答

1

爲什麼選擇QA模型?我會做一個問題has_many答案和一個問題has_many評論。另外,如果您希望用戶能夠評論其他評論,您可以選擇回答has_many評論。我覺得更容易。

+0

我的應用程序中的QA系統的主要特點(如果可以這樣稱呼的話)是隻有一個問題和一個答案。所以這個解決方案不適合我,但是謝謝。 – Ximik 2012-02-08 20:03:22