module JamRuby
  # BackingTrack analog to JamRuby::RecordedTrack
  class RecordedJamTrackTrack < ActiveRecord::Base

    belongs_to :user, :class_name => "JamRuby::User", :inverse_of => :recorded_jam_track_tracks
    belongs_to :recording, :class_name => "JamRuby::Recording", :inverse_of => :recorded_jam_track_tracks
    belongs_to :jam_track_track, :class_name => "JamRuby::JamTrackTrack", :inverse_of => :recorded_jam_track_tracks

    validates :user, presence: true
    validates :jam_track_track, presence:true

    def self.create_from_jam_track_track(jam_track_track, recording, user)
      recorded_jam_track_track = self.new
      recorded_jam_track_track.recording = recording
      recorded_jam_track_track.jam_track_track = jam_track_track
      recorded_jam_track_track.user = user
      recorded_jam_track_track.save
      recorded_jam_track_track
    end

  end
end
