0
當用戶在我的應用中查看事件時,我將與會者列表與用戶的FaceBook好友進行比較,並存儲我在EventFriends表中找到的任何交集。驗證Rails 3中user_id,friend_id,event_id的唯一性
我需要驗證表中3列的唯一性,因爲一個用戶可能有一個朋友正在參加多個事件。
任何想法?
這裏是我的模型的相關部分:
user.rb
has_many :event_users
accepts_nested_attributes_for :event_users, :allow_destroy => true
has_many :events, :through => :event_users, :order => 'start'
has_many :event_friends
accepts_nested_attributes_for :event_friends, :allow_destroy => true
event.rb
has_many :event_users, :dependent => :destroy
accepts_nested_attributes_for :event_users, :allow_destroy => true
has_many :users, :through => :event_users
has_many :event_friends, :dependent => :destroy
accepts_nested_attributes_for :event_friends, :allow_destroy => true
event_user.rb
belongs_to :event
belongs_to :user
validates_uniqueness_of :event_id, :scope => :user_id
event_friend.rb
這個表有user_id說明,事項標識和friend_id列。
belongs_to :event
belongs_to :user