band follower APIs
This commit is contained in:
parent
5d5a5d1f23
commit
7ffc952717
|
|
@ -24,6 +24,7 @@ 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/band_follower"
|
||||
|
||||
include Jampb
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ module JamRuby
|
|||
# genres
|
||||
has_and_belongs_to_many :genres, :class_name => "JamRuby::Genre", :join_table => "bands_genres"
|
||||
|
||||
# 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"
|
||||
|
||||
after_save :limit_to_three_genres
|
||||
|
||||
def photo_url
|
||||
|
|
@ -37,12 +41,12 @@ module JamRuby
|
|||
band.name = params[:name]
|
||||
end
|
||||
|
||||
# name
|
||||
# website
|
||||
unless params[:website].nil?
|
||||
band.website = params[:website]
|
||||
end
|
||||
|
||||
# name
|
||||
# biography
|
||||
unless params[:biography].nil?
|
||||
band.biography = params[:biography]
|
||||
end
|
||||
|
|
@ -56,7 +60,7 @@ module JamRuby
|
|||
band.genres.delete_all
|
||||
end
|
||||
|
||||
# loop through each instrument in the array and save to the db
|
||||
# loop through each genre in the array and save to the db
|
||||
genres.each do |genre_id|
|
||||
g = Genre.find(genre_id)
|
||||
band.genres << g
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
module JamRuby
|
||||
class BandFollower < ActiveRecord::Base
|
||||
|
||||
self.table_name = "bands_followers"
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
belongs_to :band, :class_name => "JamRuby::Band", :foreign_key => "band_id"
|
||||
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "follower_id", :inverse_of => :inverse_followers
|
||||
end
|
||||
end
|
||||
|
|
@ -24,10 +24,14 @@ module JamRuby
|
|||
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"
|
||||
|
||||
# followings
|
||||
# user followings
|
||||
has_many :followings, :class_name => "JamRuby::UserFollowing", :foreign_key => "follower_id"
|
||||
has_many :inverse_followings, :through => :followings, :source => :user, :class_name => "JamRuby::User", :foreign_key => "user_id"
|
||||
|
||||
# band followings
|
||||
has_many :band_followings, :class_name => "JamRuby::BandFollower", :foreign_key => "follower_id"
|
||||
has_many :inverse_band_followings, :through => :band_followings, :foreign_key => "band_id"
|
||||
|
||||
# favorites (needs Recording model)
|
||||
|
||||
# friends
|
||||
|
|
|
|||
Loading…
Reference in New Issue