在我的應用程序中有兩個模型用戶和事件。我想關聯兩個模型,例如,一個用戶只能創建單個事件,但可以登錄其他用戶創建的許多事件。如何在rails中關聯模型
我曾嘗試下面的關聯,但它不是爲我工作
class User < ActiveRecord::Base
has_one :event
belongs_to :event
end
class Event < ActiveRecord::Base
has_many :users
belongs_to :user
end
如何在上述條件下兩種模式相關聯。
您可能無法做到這與協會單獨。您將需要額外的代碼來操縱關聯... –