# encoding: utf-8
class SeminarSession

  include Mongoid::Document
  include Mongoid::Timestamps

  field :key
  belongs_to :seminar_main
  field :seminar_signup_ids, :type => Array, :default => []
  field :seminar_signup_contribute_ids, :type => Array, :default => []
  field :default_seminar_signup_ids, :type => Array, :default => []
  def seminar_signups
    SeminarSignup.any_of({:id.in=>self.seminar_signup_ids},{:preferred_sessions=>self.key,:seminar_session_ids.in=>[[],nil]})
  end
  def fix_seminar_signup_contribute_ids
  	@seminar_signup_ids = SeminarSignup.where(:id.in=>self.seminar_signup_ids).pluck(:id).map{|id| id.to_s}
  	self.seminar_signup_contribute_ids = SeminarSignupContribute.where(:seminar_signup_id.in=>@seminar_signup_ids).pluck(:id).map{|id| id.to_s}
  	self.save
  end
end
