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