diff --git a/lib/jam_ruby.rb b/lib/jam_ruby.rb index 63c5d0c7c..c64f8a058 100644 --- a/lib/jam_ruby.rb +++ b/lib/jam_ruby.rb @@ -34,8 +34,10 @@ require "jam_ruby/models/musician_instrument" require "jam_ruby/models/band_musician" require "jam_ruby/models/user_follower" require "jam_ruby/models/user_following" +require "jam_ruby/models/user_favorite" require "jam_ruby/models/band_follower" require "jam_ruby/models/search" +require "jam_ruby/models/recording" include Jampb diff --git a/lib/jam_ruby/models/band.rb b/lib/jam_ruby/models/band.rb index a52e5a2c5..6103f502a 100644 --- a/lib/jam_ruby/models/band.rb +++ b/lib/jam_ruby/models/band.rb @@ -8,12 +8,15 @@ module JamRuby self.primary_key = 'id' # musicians - has_many :band_musicians + has_many :band_musicians, :class_name => "JamRuby::BandMusician" 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" + # recordings + has_and_belongs_to_many :recordings, :class_name => "JamRuby::Recording", :join_table => "bands_recordings" + # followers has_many :followers, :class_name => "JamRuby::BandFollower", :foreign_key => "band_id" has_many :inverse_followers, :through => :followers, :source => :user, :class_name => "JamRuby::Band", :foreign_key => "follower_id" @@ -37,7 +40,7 @@ module JamRuby def location # TODO: implement a single string version of location; # this will be indexed into elasticsearch and returned in search - return "Austin, TX" + return "#{self.city}, #{self.state}, #{self.country}" end # helper method for creating / updating a Band diff --git a/lib/jam_ruby/models/recording.rb b/lib/jam_ruby/models/recording.rb new file mode 100644 index 000000000..2f253a04d --- /dev/null +++ b/lib/jam_ruby/models/recording.rb @@ -0,0 +1,13 @@ +module JamRuby + class Recording < ActiveRecord::Base + + self.primary_key = 'id' + + # musicians + has_and_belongs_to_many :users, :class_name => "JamRuby::User", :join_table => "musicians_recordings" + + # bands + has_and_belongs_to_many :bands, :class_name => "JamRuby::Band", :join_table => "bands_recordings" + + 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 7a3c0c56a..263405615 100644 --- a/lib/jam_ruby/models/user.rb +++ b/lib/jam_ruby/models/user.rb @@ -24,6 +24,9 @@ module JamRuby has_many :band_musicians has_many :bands, :through => :band_musicians, :class_name => "JamRuby::Band" + # recordings + has_and_belongs_to_many :recordings, :class_name => "JamRuby::Recording", :join_table => "musicians_recordings" + # followers has_many :followers, :class_name => "JamRuby::UserFollower", :foreign_key => "user_id" has_many :inverse_followers, :through => :followers, :source => :user, :class_name => "JamRuby::User", :foreign_key => "follower_id" @@ -36,7 +39,9 @@ module JamRuby has_many :band_followings, :class_name => "JamRuby::BandFollower", :foreign_key => "follower_id" has_many :inverse_band_followings, :through => :band_followings, :class_name => "JamRuby::Band", :foreign_key => "band_id" - # favorites (needs Recording model) + # favorites + has_many :favorites, :class_name => "JamRuby::UserFavorite", :foreign_key => "recording_id" + has_many :inverse_favorites, :through => :favorites, :source => :user, :class_name => "JamRuby::User", :foreign_key => "user_id" # friends has_many :friendships, :class_name => "JamRuby::Friendship", :foreign_key => "user_id" @@ -52,7 +57,6 @@ module JamRuby has_many :received_invitations, :foreign_key => "receiver_id", :inverse_of => :receiver, :class_name => "JamRuby::Invitation" has_many :sent_invitations, :foreign_key => "sender_id", :inverse_of => :sender, :class_name => "JamRuby::Invitation" - # This causes the authenticate method to be generated (among other stuff) has_secure_password @@ -82,9 +86,7 @@ module JamRuby end def location - # TODO: implement a single string version of location; - # this will be indexed into elasticsearch and returned in search - return "Austin, TX" + return "#{self.city}, #{self.state}, #{self.country}" end def should_validate_password? diff --git a/lib/jam_ruby/models/user_favorite.rb b/lib/jam_ruby/models/user_favorite.rb new file mode 100644 index 000000000..5de3e8504 --- /dev/null +++ b/lib/jam_ruby/models/user_favorite.rb @@ -0,0 +1,10 @@ +module JamRuby + class UserFavorite < ActiveRecord::Base + + self.table_name = "users_favorites" + + self.primary_key = 'id' + + belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id", :inverse_of => :inverse_favorites + end +end \ No newline at end of file