1
我有一個傳統的Rails 3應用程序,我試圖在兩個模型之間建立一個簡單的HABTM關係:VolunteerCircle和User。我在另外兩個模型中也有同樣的關聯。Rails 3 HABTM產生ActiveRecord :: Associations :: CollectionProxy對象
的關聯如下:
VolunteerCircle型號:
class VolunteerCircle < ActiveRecord::Base
#...
has_and_belongs_to_many :users
# ...
end
用戶模式:
class User < ActiveRecord::Base
#...
has_and_belongs_to_many :volunteer_circles
#...
end
這裏是遷移:
class CreateVolunteerCirclesUsers < ActiveRecord::Migration
def change
create_table :volunteer_circles_users, id: false do |t|
t.belongs_to :volunteer_circle, index: true
t.belongs_to :user, index: true
end
end
end
當我打電話#用戶一個VolunteerCircle對象(反之亦然),Rails咳嗽一個ActiveRecord :: Associations :: CollectionProxy對象。
volunteer_circles_users表在數據庫中對我來說很合適。我在這裏錯過了什麼?
此外,我知道HABTMT的優越性。超出我的控制範圍在這裏指定HABTM。
非常感謝!
了有關按字母順序排列的說明釘它。感謝您的信息! – cmhobbs