Album associations
This commit is contained in:
		
							parent
							
								
									d142c516be
								
							
						
					
					
						commit
						f328c319ed
					
				@ -1,5 +1,14 @@
 | 
			
		||||
class Album < ActiveRecord::Base
 | 
			
		||||
  belongs_to :artist
 | 
			
		||||
  has_many :tracks, :order => 'bonus ASC, position ASC', :dependent => :destroy
 | 
			
		||||
  has_many :local_brainz_releases, :class_name => 'LocalBrainz::Release', :dependent => :destroy
 | 
			
		||||
  has_many :local_brainz_cached_releases, :class_name => 'LocalBrainz::CachedRelease', :dependent => :destroy
 | 
			
		||||
  has_many :album_formats
 | 
			
		||||
  has_many :release_formats, :through => :album_formats
 | 
			
		||||
  
 | 
			
		||||
  default_scope where(:master => true)
 | 
			
		||||
  scope :with_non_masters, where(:master => [true, false])
 | 
			
		||||
  
 | 
			
		||||
  def self.with_format f
 | 
			
		||||
    joins(:release_formats).where(:release_formats => { :hash => f.to_s })
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
class AlbumFormat < ActiveRecord::Base
 | 
			
		||||
  belongs_to :album
 | 
			
		||||
  belongs_to :format
 | 
			
		||||
  belongs_to :release_format
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -1,2 +1,3 @@
 | 
			
		||||
class ReleaseFormat < ActiveRecord::Base
 | 
			
		||||
  has_many :albums, :through => :album_formats
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
class Track < ActiveRecord::Base
 | 
			
		||||
  belongs_to :album
 | 
			
		||||
  has_many :track_artists
 | 
			
		||||
  has_many :artists, :through => :track_artists
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user