VRFS-81 recordings and favorites
This commit is contained in:
parent
ecf792b404
commit
3fd79527ef
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue