module JamRuby
  class PlayablePlay < ActiveRecord::Base
    self.table_name = "playable_plays"

    belongs_to :playable, :polymorphic => :true
    # VRFS-2916 jam_tracks.id is varchar: REMOVE
    #belongs_to :jam_track, :foreign_key => :jam_track_id
    belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "player_id"
    belongs_to :claimed_recording, :class_name => "JamRuby::ClaimedRecording", :foreign_key => "claimed_recording_id"

    validate do
      # VRFS-2916 jam_tracks.id is varchar: REMOVE
      #if !playable_id && !jam_track_id
      #  self.errors[:base] << 'No playable instance detected'
      #end

      # VRFS-2916 jam_tracks.id is varchar: ADD
      if !playable_id
         self.errors[:base] << 'No playable instance detected'
       end

      if !user
        self.errors[:base] << 'No user detected'
      end
    end

  end
end
