jam-cloud/ruby/lib/jam_ruby/models/performance_sample.rb

19 lines
905 B
Ruby

module JamRuby
class PerformanceSample < ActiveRecord::Base
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id"
belongs_to :claimed_recording, :class_name => "JamRuby::ClaimedRecording" :foreign_key => "claimed_recording_id"
validates :user_type_recording_unique :if => lambda { |p| p.type == "jamkazam" }
validates :user_type_service_unique :if => lambda { |p| p.type != "jamkazam" }
def user_type_recording_unique
match = PerformanceSample.exists?(:user_id => user.id, :claimed_recording_id => self.claimed_recording_id)
raise "You already have this JamKazam recording listed as a sample" if match
end
def user_type_service_unique
match = PerformanceSample.exists?(:user_id => user.id, :service_id => self.service_id)
raise "You already have this #{self.type} sample listed (#{self.service_id}." if match
end
end
end