48 lines
1.5 KiB
Ruby
48 lines
1.5 KiB
Ruby
module JamRuby
|
|
class RsvpRequest < ActiveRecord::Base
|
|
|
|
belongs_to :user, :class_name => "JamRuby::User"
|
|
has_many :rsvp_request_rsvp_slots, :class_name => "JamRuby::RsvpRequestRsvpSlot"
|
|
has_many :rsvp_slots, :class_name => "JamRuby::RsvpSlot", :through => :rsvp_requests_rsvp_slots
|
|
|
|
# validates :message, length: {maximum: 1000}, no_profanity: true
|
|
|
|
validates :canceled, :inclusion => {:in => [nil, true, false]}
|
|
|
|
# def self.create(params)
|
|
# # slot_ids =
|
|
# rsvp = RsvpRequest.new
|
|
# # rsv
|
|
# rsvp.save
|
|
# end
|
|
|
|
def self.requests_by_session(session, user = nil)
|
|
query = RsvpRequest
|
|
.includes(:user)
|
|
.joins(
|
|
%Q{
|
|
INNER JOIN
|
|
rsvp_requests_rsvp_slots rrrs
|
|
ON
|
|
rrrs.rsvp_request_id = rsvp_requests.id
|
|
INNER JOIN
|
|
rsvp_slots rs
|
|
ON rs.id = rrrs.rsvp_slot_id
|
|
}
|
|
)
|
|
.where(
|
|
%Q{
|
|
rs.music_session_id = '#{session.id}'
|
|
}
|
|
)
|
|
|
|
query = query.where("rsvp_requests.user_id = '#{user.id}'") unless user.nil?
|
|
return query
|
|
end
|
|
|
|
# XXX we need to validate that only one RsvpRequest.chosen = true for a given RsvpSlot
|
|
# in other words, you can have many requests to a slot, but only 0 or 1 rsvp_request.chosen = true)
|
|
end
|
|
|
|
end
|