【发布时间】:2011-05-17 17:51:40
【问题描述】:
class Allowedevent < ActiveRecord::Base
:belongs_to :room
:belongs_to :event
end
class Room < ActiveRecord::Base
:has_many :allowedevents
:has_many :events => :through => allowedevents
end
class Event< ActiveRecord::Base
:has_many :allowedevents
:has_many :rooms=> :through => allowedevents
end
我很难将上述关系放入表格或在控制台中玩弄它们。
问题:
-
现在假设我保存了一个房间,我是否必须将 ID 显式添加到
allowedevents表中? 我必须这样做吗?房间 = Room.new; room.title = "测试"; room.allowedevents = ""...?
从上面可以看出,我不知道如何保存实际记录。
基本上我想问如何使用上述关系将房间保存到具有许多
allowedevents的数据库中。我是否必须遍历用户输入并将每个输入保存到allowedevents?有没有更好的办法?我从 railscasts 剧集中得到了以上内容,railscasts 上是否有一个剧集真正说明了如何在前端使用它?
【问题讨论】:
标签: ruby-on-rails-3 activerecord railscasts