我有一個用戶表和一個角色表。製作model1_model2表時,我是創建一個模型還是?
我希望做一個表,如:
model1_model2
與列:
model1_id
model2_id
other_column int
other_column2 int
因爲我需要公開的其他列(比ID的除外),我只是做了一個模型,匹配此表並將其稱爲Module1Module2
?
我有一個用戶表和一個角色表。製作model1_model2表時,我是創建一個模型還是?
我希望做一個表,如:
model1_model2
與列:
model1_id
model2_id
other_column int
other_column2 int
因爲我需要公開的其他列(比ID的除外),我只是做了一個模型,匹配此表並將其稱爲Module1Module2
?
它看起來像你正在尋找has_and_belongs_to_many
relationship。
除非它描述兩個模型之間的關係,否則has_and_belongs_to_many
不適用,您必須專門爲該關係創建模型,否則不應該將信息放入連接表中。
差不多.. 這是與外觀極好的資源你在尋找什麼: http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association