1
0
Fork 0
oldhaven/app/models/music/album.rb

29 lines
638 B
Ruby

class Album < ActiveRecord::Base
belongs_to :artist
has_many :tracks, :conditions => ['position > 0'], :order => 'bonus ASC, position ASC', :dependent => :destroy
has_many :album_formats
has_many :release_formats, :through => :album_formats
default_scope where(:master => true)
after_save :clear_artist_cache
def self.with_format f
joins(:release_formats).where(:release_formats => { :hash => f.to_s })
end
def serialize
{
name: name,
pic_url: pic_url,
year: year,
tracks: tracks.map(&:serialize)
}
end
private
def clear_artist_cache
artist.clear_cache
end
end