diff --git a/lib/jam_ruby.rb b/lib/jam_ruby.rb index 8887749ea..4cd423c8e 100644 --- a/lib/jam_ruby.rb +++ b/lib/jam_ruby.rb @@ -19,7 +19,8 @@ require "jam_ruby/models/music_session" require "jam_ruby/models/invitation" require "jam_ruby/models/friend_request" require "jam_ruby/models/instrument" -require "jam_ruby/models/user_instrument" +require "jam_ruby/models/musician_instrument" +require "jam_ruby/models/band_musician" include Jampb diff --git a/lib/jam_ruby/models/band.rb b/lib/jam_ruby/models/band.rb index 663a2a40d..904408115 100644 --- a/lib/jam_ruby/models/band.rb +++ b/lib/jam_ruby/models/band.rb @@ -1,21 +1,23 @@ module JamRuby class Band < ActiveRecord::Base - attr_accessor :photo_url, :logo_url - self.primary_key = 'id' - has_and_belongs_to_many :users, :class_name => "JamRuby::User" - has_many :genres, :class_name => "JamRuby::Genre" + # musicians + has_many :band_musicians + has_many :users, :through => :band_musicians, :class_name => "JamRuby::User" + + # genres + has_and_belongs_to_many :genres, :class_name => "JamRuby::Genre", :join_table => "bands_genres" def photo_url # TODO: move image path to config - @photo_url = "http://www.jamkazam.com/images/bands/photos/#{self.id}.gif"; + @photo_url = "http://www.jamkazam.com/images/bands/photos/#{self.id}.gif" end def logo_url # TODO: move image path to config - @logo_url = "http://www.jamkazam.com/images/bands/logos/#{self.id}.gif"; + @logo_url = "http://www.jamkazam.com/images/bands/logos/#{self.id}.gif" end end diff --git a/lib/jam_ruby/models/band_musician.rb b/lib/jam_ruby/models/band_musician.rb new file mode 100644 index 000000000..a750bafe4 --- /dev/null +++ b/lib/jam_ruby/models/band_musician.rb @@ -0,0 +1,29 @@ +module JamRuby + class BandMusician < ActiveRecord::Base + + self.table_name = "bands_musicians" + + self.primary_key = 'id' + + belongs_to :user + belongs_to :band + + # name, genres, photo_url, and logo_url are needed here for the RABL file + def name + @name = self.band.name + end + + def genres + @genres = self.band.genres + end + + def photo_url + @photo_url = self.band.photo_url + end + + def logo_url + @logo_url = self.band.logo_url + end + + end +end \ No newline at end of file diff --git a/lib/jam_ruby/models/genre.rb b/lib/jam_ruby/models/genre.rb index fb3d692a0..1649825e2 100644 --- a/lib/jam_ruby/models/genre.rb +++ b/lib/jam_ruby/models/genre.rb @@ -3,7 +3,10 @@ module JamRuby self.primary_key = 'id' - has_and_belongs_to_many :bands, :class_name => "JamRuby::Band" + # bands + has_and_belongs_to_many :bands, :class_name => "JamRuby::Band", :join_table => "bands_genres" + + # music sessions has_and_belongs_to_many :music_sessions, :class_name => "JamRuby::MusicSession", :join_table => "genres_music_sessions" end diff --git a/lib/jam_ruby/models/instrument.rb b/lib/jam_ruby/models/instrument.rb index db3019be9..9119d6a94 100644 --- a/lib/jam_ruby/models/instrument.rb +++ b/lib/jam_ruby/models/instrument.rb @@ -4,8 +4,8 @@ module JamRuby self.primary_key = 'id' # users - has_many :user_instruments - has_many :users, :through => :user_instruments, :class_name => "JamRuby::User" + has_many :musician_instruments + has_many :users, :through => :musician_instruments, :class_name => "JamRuby::User" # music sessions has_and_belongs_to_many :music_sessions, :class_name => "JamRuby::MusicSession", :join_table => "genres_music_sessions" diff --git a/lib/jam_ruby/models/musician_instrument.rb b/lib/jam_ruby/models/musician_instrument.rb new file mode 100644 index 000000000..2fd11e64e --- /dev/null +++ b/lib/jam_ruby/models/musician_instrument.rb @@ -0,0 +1,16 @@ +module JamRuby + class MusicianInstrument < ActiveRecord::Base + + self.table_name = "musicians_instruments" + + self.primary_key = 'id' + + belongs_to :user + belongs_to :instrument + + def description + @description = self.instrument.description + end + + end +end \ No newline at end of file diff --git a/lib/jam_ruby/models/user.rb b/lib/jam_ruby/models/user.rb index f5389e01b..f80869d61 100644 --- a/lib/jam_ruby/models/user.rb +++ b/lib/jam_ruby/models/user.rb @@ -13,11 +13,12 @@ module JamRuby has_many :friend_requests, :class_name => "JamRuby::FriendRequest" # instruments - has_many :user_instruments - has_many :instruments, :through => :user_instruments, :class_name => "JamRuby::Instrument" + has_many :musician_instruments + has_many :instruments, :through => :musician_instruments, :class_name => "JamRuby::Instrument" # bands - has_and_belongs_to_many :bands, :class_name => "JamRuby::Band" + has_many :band_musicians + has_many :bands, :through => :band_musicians, :class_name => "JamRuby::Band" # friends has_many :friendships, :class_name => "JamRuby::Friendship", :foreign_key => "user_id"