Merge branch 'master' of bitbucket.org:jamkazam/jam-ruby

This commit is contained in:
Seth Call 2012-11-17 21:00:03 -06:00
commit e372f6858e
5 changed files with 37 additions and 7 deletions

View File

@ -36,8 +36,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

View File

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

View File

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

View File

@ -27,6 +27,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"
@ -39,7 +42,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"
@ -59,7 +64,6 @@ module JamRuby
has_many :received_fan_invitations, :foreign_key => "receiver_id", :inverse_of => :receiver, :class_name => "JamRuby::FanInvitation"
has_many :sent_fan_invitations, :foreign_key => "sender_id", :inverse_of => :sender, :class_name => "JamRuby::FanInvitation"
# This causes the authenticate method to be generated (among other stuff)
has_secure_password
@ -93,9 +97,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?

View File

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