add bands to user details API, renamed band/musician related user models

This commit is contained in:
Brian Smith 2012-10-30 01:42:16 -04:00
parent 6ba6b7d595
commit bc3b0e5c57
7 changed files with 65 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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"